Page 1 of 1

clang completion

Posted: Tue May 20, 2014 10:44 am
by josee
How does it work?

I used "codelitegcc gcc ..." as my compilation command in my Makefile.
Then some "projekte/codelite/.codelite/compilation.db.txt" is produced which is cleared
after some time and a binary file "projekte/codelite/.codelite/compilation.db" remains.

Trying clang completion in the editor for an ansi C99 file (after having it switched on) gives the error message:

clang: code completion error
-----------------------------------

unknown type name 'uint8_t'
unknown type name 'uint16_t'
unknown type name 'trie_t'
unknown type name 'bool'
use of uncdeclared identifier 'EEXIST'

The standard integer types uint8_t,... and system error codes 'EEXIST' will be included and ctag recognizes them. But clang does not.
Is there something I could do about it?

Re: clang completion

Posted: Tue May 20, 2014 11:40 am
by eranif
Are you using PCH?
If so, the clang code completion does not support that.
You will need to make sure that all the headers are there.

You could also try this:
Go to: Settings -> Global editor preferences -> Misc -> Log
Change the log verbosity to 'Debug'

from a terminal:
tail -f ~/.codelite/codelite.log &

Now, clear clang cache (Settings -> Tags Settings -> Clang -> Cache -> Clear button)

try to code complete something with clang, and you should see in the log file what codelite is passing to clang.
Make sure it passes the correct build line (headers, defines and other switches)

This might give you a hint of why its not working for you

Eran

Re: clang completion

Posted: Tue May 20, 2014 12:09 pm
by josee
Thanks for the fast reply. I am not using pre compiled headers.

The output of tail -f ~/.codelite/codelite.log is

==========> ClangDriver::CodeCompletion() started <==============
[ 09:55:01:156 DBG ] Loading compilation flags for file: /jsprojekt/JS/C-kern/ds/inmem/trie.c
[ 09:55:01:156 DBG ] Loaded compilation flags:
[ 09:55:01:183 DBG ] ==========> [ ClangPchMakerThread ] ProcessRequest started: /jsprojekt/JS/C-kern/ds/inmem/trie.c
[ 09:55:01:184 DBG ] ClangWorkerThread:: processing request 0
[ 09:55:01:184 DBG ] ClangWorkerThread:: found cached TU: (
[ 09:55:01:184 DBG ] Command Line Argument: -I/usr/include
[ 09:55:01:184 DBG ] Command Line Argument: -I/usr/include/i386-linux-gnu
[ 09:55:01:184 DBG ] Command Line Argument:
[ 09:55:01:184 DBG ] Command Line Argument: -w
[ 09:55:01:184 DBG ] Command Line Argument: -ferror-limit=1000
[ 09:55:01:184 DBG ] Command Line Argument: -nobuiltininc
[ 09:55:01:184 DBG ] Calling clang_parseTranslationUnit...
[ 09:55:01:211 DBG ] Calling clang_parseTranslationUnit... done
[ 09:55:01:211 DBG ] Calling clang_reparseTranslationUnit...
[ 09:55:01:234 DBG ] Calling clang_reparseTranslationUnit... done
[ 09:55:01:234 DBG ] Calling clang_codeCompleteAt...
[ 09:55:01:236 DBG ] Location: /jsprojekt/JS/C-kern/ds/inmem/trie.c:3753:7
[ 09:55:01:243 DBG ] Calling clang_codeCompleteAt... done
[ 09:55:01:244 DBG ] Found 317 matches
[ 09:55:01:244 DBG ] Completion diagnostic [3]: unknown type name 'uint8_t'
...

I retried after adding the include directory under Tags -> Tags Settings -> Clang

[ 09:57:41:477 DBG ] ==========> ClangDriver::CodeCompletion() started <==============
[ 09:57:41:487 DBG ] Loading compilation flags for file: /jsprojekt/JS/C-kern/ds/inmem/trie.c
[ 09:57:41:487 DBG ] Loaded compilation flags:
[ 09:57:41:500 DBG ] ==========> [ ClangPchMakerThread ] ProcessRequest started: /jsprojekt/JS/C-kern/ds/inmem/trie.c
[ 09:57:41:500 DBG ] ClangWorkerThread:: processing request 0
[ 09:57:41:500 DBG ] ClangWorkerThread:: found cached TU: (
[ 09:57:41:501 DBG ] Command Line Argument: -I/usr/include
[ 09:57:41:501 DBG ] Command Line Argument: -I/usr/include/i386-linux-gnu
[ 09:57:41:501 DBG ] Command Line Argument: -I/jsprojekt/JS
[ 09:57:41:501 DBG ] Command Line Argument:
[ 09:57:41:501 DBG ] Command Line Argument: -w
[ 09:57:41:501 DBG ] Command Line Argument: -ferror-limit=1000
[ 09:57:41:501 DBG ] Command Line Argument: -nobuiltininc
[ 09:57:41:501 DBG ] Calling clang_parseTranslationUnit...
[ 09:57:41:653 DBG ] Calling clang_parseTranslationUnit... done
[ 09:57:41:653 DBG ] Calling clang_reparseTranslationUnit...
[ 09:57:41:928 DBG ] Calling clang_reparseTranslationUnit... done
[ 09:57:41:928 DBG ] Calling clang_codeCompleteAt...
[ 09:57:41:929 DBG ] Location: /jsprojekt/JS/C-kern/ds/inmem/trie.c:3753:7
[ 09:57:41:942 DBG ] Calling clang_codeCompleteAt... done
[ 09:57:41:943 DBG ] Found 5835 matches
[ 09:57:41:943 DBG ] Completion diagnostic [3]: unknown type name 'bool'
[ 09:57:41:943 DBG ] caching Translation Unit file: /jsprojekt/JS/C-kern/ds/inmem/trie.c, 0xaaf01a80
[ 09:57:41:943 DBG ] ==========> [ ClangPchMakerThread ] PCH creation ended successfully <==============

Now only bool is unknown - a stark improvement !

But the problem (so it seems to me) is all other command line arguments are missing.

Here is an example entry from compilation.db.txt:

/jsprojekt/JS/C-kern/platform/Linux/vm.c|/jsprojekt/JS|gcc -DKONFIG_UNITTEST -DKONFIG_USERINTERFACE=(X11|EGL) -I/usr/include/freetype2 -I. -g -fstack-protector-all -MMD -std=gnu1x -pedantic -Wall -Wextra -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -Wstrict-prototypes -Wformat-nonliteral -Wformat-y2k -Wstrict-overflow=5 -c -o bin/Debug/unittest/C-kern!platform!Linux!vm.c.o C-kern/platform/Linux/vm.c

Re: clang completion

Posted: Tue May 20, 2014 12:18 pm
by eranif
You should not need to add include paths manually, they should be there automatically.
Can you locate the entry for that specific file in the database? (i.e. the file "/jsprojekt/JS/C-kern/ds/inmem/trie.c")

Eran

Re: clang completion

Posted: Tue May 20, 2014 12:37 pm
by josee
The entry in projekte/codelite/.codelite/compilation.db.txt for trie.c is

/jsprojekt/JS/C-kern/ds/inmem/trie.c|/jsprojekt/JS|gcc -DKONFIG_UNITTEST -DKONFIG_USERINTERFACE=(X11|EGL) -I/usr/include/freetype2 -I. -g -fstack-protector-all -MMD -std=gnu1x -pedantic -Wall -Wextra -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -Wstrict-prototypes -Wformat-nonliteral -Wformat-y2k -Wstrict-overflow=5 -c -o bin/Debug/unittest/C-kern!ds!inmem!trie.c.o C-kern/ds/inmem/trie.c

Does it help to post the compilation.db (if the forum supports it)?

Re: clang completion

Posted: Tue May 20, 2014 1:07 pm
by eranif
The line is enough

Eran