Trouble with code completion

General questions regarding the usage of CodeLite
frozen
CodeLite Curious
Posts: 7
Joined: Fri Jul 29, 2011 4:49 pm
Genuine User: Yes
IDE Question: c++
Contact:

Trouble with code completion

Post by frozen »

Hi!

I'm using Codelite v3.0.5007 (latest trunk as of today). OS is Debian testing/unstable.

My problem is:
Whereever I write something like

Code: Select all

#include <string>
std::string test; test.
and then type CTRL+SPACE nothing happens.

Same with this:

Code: Select all

#include <string>
using std::string; string test; test.
Pressing CTRL+SPACE after typing

Code: Select all

#include <string>
using namespace std; stri
does NOT provide std::string, string or anything like this. Some StringToXXX functions are offered though.

Under "Settings->Tags Settings" I find quite some paths under "ctags->Include Files" including the one containing string.h and all the other files.
There are no excluded paths.
"Scan all included files to locate 'using namespace' statements" is set.

Workspace tag settings are empty.

Before pressing CTRL+SPACE I press CTRL+S to save the file and trigger tagging.

Retagging the workspace by using "Workspace->Retag Workspace (Full)" didn't help.

Is this a bug or am I doing something wrong?

Thanks!

frozen
User avatar
eranif
CodeLite Plugin
Posts: 6146
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Trouble with code completion

Post by eranif »

1) Make sure that under 'tags settings | clang | use clang completion over ctags' is not checked (unless you have clang installed)

2) It is working fine here. Is your file is part of a project?

3) Please paste here the content of your ctags -> include files

4) Do you get any errors in the 'trace' tab?

Eran
Make sure you have read the HOW TO POST thread
frozen
CodeLite Curious
Posts: 7
Joined: Fri Jul 29, 2011 4:49 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Trouble with code completion

Post by frozen »

Hello Eran.

Thanks for helping out.

1) Yes, clang is not checked.

2) Yes, it is.

3)

Code: Select all

/usr/include/c++/4.6
/usr/include/c++/4.6/x86_64-linux-gnu
/usr/include/c++/4.6/backward
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include-fixed
/usr/include
/usr/include/qt4/QtCore
/usr/include/qt4/QtGui
/usr/include/qt4/QtXml
/usr/include/wx-2.8
Some of these are not needed, but they do exist and contain files.

4) No errors.. Last line created by a full retag just seconds ago is:

Code: Select all

09:59:55: INFO: Retag workspace completed in 15 seconds (535 files were scanned)
I hope this helps..

frozen
User avatar
eranif
CodeLite Plugin
Posts: 6146
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Trouble with code completion

Post by eranif »

frozen wrote:/usr/include/c++/4.6
Maybe there are some nasty macros changes in 4.6 ...

I will need to get my hands over gcc 4.6 and see what are the main changes

Eran
Make sure you have read the HOW TO POST thread
frozen
CodeLite Curious
Posts: 7
Joined: Fri Jul 29, 2011 4:49 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Trouble with code completion

Post by frozen »

I see. I hope this doesn't mean too much trouble for you.. Thank you very much!

frozen
User avatar
eranif
CodeLite Plugin
Posts: 6146
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Trouble with code completion

Post by eranif »

You could install clang binary and use it

32 bit:
http://llvm.org/releases/2.9/clang+llvm ... -linux.tgz

64 bit:
http://llvm.org/releases/2.9/clang+llvm ... ux.tar.bz2

extract the tar file, and add its bin directory to the PATH (or point codelite to clang binary from 'settings | tags settings | clang | cache')
Tick the to enable the clang completion

Eran
Make sure you have read the HOW TO POST thread
frozen
CodeLite Curious
Posts: 7
Joined: Fri Jul 29, 2011 4:49 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Trouble with code completion

Post by frozen »

Hello Eran,

I tried using clang in the following ways, always with the same behaviour as described in the first post:

1) Installed the debian clang package (2.7).
2) Used the binary from the package you suggested (2.9)

I checked the following items:
"Enable clang code completion"
"Use clang completion over ctags ccompletion"

I tried to use the same search paths than used by ctags and just the suggested ones.

Caching policy is set to "On file load".

I cleared the cache and did a full retag of the workspace between each try.

Without success... Something seems to be pretty wrong in my system..

Just to make sure I created a new workspace and a new project inside. In this new main.cpp I tried it again - with the same result. Retagging the whole workspace didn't help again.

Thanks for the suggestion. Do you have any idea left?

frozen
User avatar
eranif
CodeLite Plugin
Posts: 6146
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Trouble with code completion

Post by eranif »

frozen wrote:1) Installed the debian clang package (2.7).
Uninstall it
codelite requires clang 2.8 and up
frozen wrote:"Use clang completion over ctags ccompletion"
Dont. Only enable clang - dont make it the main completion engine (not recommended)
frozen wrote: full retag of the workspace between each try.
Retag has no effect on the clang completion.

To be able to see whats wrong, you might want to enable the logging of codelite and view why clang is failing.
basically, if your code is compile-able, clang should be able to compile it and suggest completion.

To enable the logging:
settings | global editor preferences | misc | Logging
and change the debug level to 'Debug'

from a terminal run:

Code: Select all

tail -f ~/.codelite/codelite.log &
Try completing something again and view the log (better yet, paste the output here)

Eran
Make sure you have read the HOW TO POST thread
frozen
CodeLite Curious
Posts: 7
Joined: Fri Jul 29, 2011 4:49 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: Trouble with code completion

Post by frozen »

Ok, the debian version is uninstalled and clang is no longer used over ctags..

Logging output:

Code: Select all

[ 19:35:36:335 DBG ] ClangCodeCompletion::OnFileLoaded() START
[ 19:35:36:335 DBG ]  ==========> ClangDriver::CodeCompletion() started <==============
[ 19:35:36:335 DBG ] Calling DoRemoveAllIncludeStatements()
[ 19:35:36:336 DBG ] Stripping include: wx/wx.h
[ 19:35:36:336 DBG ] Stripping include: string
[ 19:35:36:336 DBG ] Calling DoRemoveAllIncludeStatements()- ENDED
[ 19:35:36:336 DBG ] DoPrepareCompilationArgs(): Project=ccompletiontest, Conf=Debug
[ 19:35:36:336 DBG ] Queued request to create PCH for file: main.cpp
[ 19:35:36:336 DBG ] ClangCodeCompletion::OnFileLoaded() ENDED
[ 19:35:36:375 DBG ]  ==========> [ ClangPchMakerThread ] PCH creation started <==============
[ 19:35:36:376 DBG ] Executing: /bin/sh -c 'cd "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest" && "/home/frozen/codelite_svn/clang/clang+llvm-2.9-x86_64-linux.tar/bin/clang" -cc1 -fexceptions  -I"/usr/include/wx-2.8"  -I"/usr/include/c++/4.6"  -I"/usr/include/c++/4.6/x86_64-linux-gnu"  -I"/usr/include/c++/4.6/backward"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include"  -I"/usr/local/include"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include-fixed"  -I"/usr/include/x86_64-linux-gnu"  -I"/usr/include"  -I. -g -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread  -D__WX__ -w "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest/main.cpp" -E > "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.1" 2>&1'
[ 19:35:36:476 DBG ] Calling DoRemoveAllIncludeStatements()
[ 19:35:36:477 DBG ] Stripping include: wx/wx.h
[ 19:35:36:477 DBG ] Stripping include: string
[ 19:35:36:477 DBG ] Calling DoRemoveAllIncludeStatements()- ENDED
[ 19:35:36:603 DBG ] Executing: /bin/sh -c 'cd "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest" && "/home/frozen/codelite_svn/clang/clang+llvm-2.9-x86_64-linux.tar/bin/clang" -cc1 -fexceptions -x c++-header  -I"/usr/include/wx-2.8"  -I"/usr/include/c++/4.6"  -I"/usr/include/c++/4.6/x86_64-linux-gnu"  -I"/usr/include/c++/4.6/backward"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include"  -I"/usr/local/include"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include-fixed"  -I"/usr/include/x86_64-linux-gnu"  -I"/usr/include"  -I. -g -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread  -D__WX__ -w "/home/frozen/.codelite/clang_cache/main_cpp__H__.h" -emit-pch -o "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.pch" > "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.pch.output" 2>&1'
[ 19:35:37:151 DBG ]  ==========> [ ClangPchMakerThread ] PCH creation ended with error <==============
[ 19:35:39:481 DBG ] Failed to resolve test .
[ 19:35:39:481 DBG ]  ==========> ClangDriver::CodeCompletion() started <==============
[ 19:35:39:481 DBG ] Calling DoRemoveAllIncludeStatements()
[ 19:35:39:481 DBG ] Stripping include: wx/wx.h
[ 19:35:39:481 DBG ] Stripping include: string
[ 19:35:39:481 DBG ] Calling DoRemoveAllIncludeStatements()- ENDED
[ 19:35:39:482 DBG ] DoPrepareCompilationArgs(): Project=ccompletiontest, Conf=Debug
[ 19:35:39:482 DBG ] Queued request to create PCH for file: main.cpp
[ 19:35:39:562 DBG ]  ==========> [ ClangPchMakerThread ] PCH creation started <==============
[ 19:35:39:562 DBG ] Executing: /bin/sh -c 'cd "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest" && "/home/frozen/codelite_svn/clang/clang+llvm-2.9-x86_64-linux.tar/bin/clang" -cc1 -fexceptions  -I"/usr/include/wx-2.8"  -I"/usr/include/c++/4.6"  -I"/usr/include/c++/4.6/x86_64-linux-gnu"  -I"/usr/include/c++/4.6/backward"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include"  -I"/usr/local/include"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include-fixed"  -I"/usr/include/x86_64-linux-gnu"  -I"/usr/include"  -I. -g -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread  -D__WX__ -w "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest/main.cpp" -E > "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.1" 2>&1'
[ 19:35:39:665 DBG ] Calling DoRemoveAllIncludeStatements()
[ 19:35:39:666 DBG ] Stripping include: wx/wx.h
[ 19:35:39:666 DBG ] Stripping include: string
[ 19:35:39:666 DBG ] Calling DoRemoveAllIncludeStatements()- ENDED
[ 19:35:39:787 DBG ] Executing: /bin/sh -c 'cd "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest" && "/home/frozen/codelite_svn/clang/clang+llvm-2.9-x86_64-linux.tar/bin/clang" -cc1 -fexceptions -x c++-header  -I"/usr/include/wx-2.8"  -I"/usr/include/c++/4.6"  -I"/usr/include/c++/4.6/x86_64-linux-gnu"  -I"/usr/include/c++/4.6/backward"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include"  -I"/usr/local/include"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include-fixed"  -I"/usr/include/x86_64-linux-gnu"  -I"/usr/include"  -I. -g -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread  -D__WX__ -w "/home/frozen/.codelite/clang_cache/main_cpp__H__.h" -emit-pch -o "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.pch" > "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.pch.output" 2>&1'
[ 19:35:40:337 DBG ]  ==========> [ ClangPchMakerThread ] PCH creation ended with error <==============
[ 19:35:42:302 DBG ] Aborting PCH caching...
[ 19:35:42:303 DBG ] ClangCodeCompletion::OnFileLoaded() START
The main.cpp:

Code: Select all

#include <wx/wx.h>
#include <string>

// application class
class wxMiniApp : public wxApp
{
    public:
		// function called at the application initialization
        virtual bool OnInit();

		// event handler for button click
        void OnClick(wxCommandEvent& event) { GetTopWindow()->Close(); }
};

IMPLEMENT_APP(wxMiniApp);

bool wxMiniApp::OnInit()
{
	std::string test;
	test.
	// create a new frame and set it as the top most application window
    SetTopWindow( new wxFrame( NULL, -1, wxT(""), wxDefaultPosition, wxSize( 100, 50) ) );

	// create new button and assign it to the main frame
    new wxButton( GetTopWindow(), wxID_EXIT, wxT("Click!") );

	// connect button click event with event handler
    Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxMiniApp::OnClick) );

	// show main frame
    GetTopWindow()->Show();

	// enter the application's main loop
    return true;
}
Additional info:

Code: Select all

$ cat ~/.codelite/clang_cache/main_cpp__H__.h 
#include "/usr/include/wx-2.8/wx/wx.h"
#include "/usr/include/c++/4.6/string"
and

Code: Select all

$ ls ~/.codelite/clang_cache/
main_cpp__H__.h
Does this help you? The line " ==========> [ ClangPchMakerThread ] PCH creation ended with error <==============" is interesting to me - but not helping..

So I did the following:

Code: Select all

$ cd "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest" && "/home/frozen/codelite_svn/clang/clang+llvm-2.9-x86_64-linux.tar/bin/clang" -cc1 -fexceptions -x c++-header  -I"/usr/include/wx-2.8"  -I"/usr/include/c++/4.6"  -I"/usr/include/c++/4.6/x86_64-linux-gnu"  -I"/usr/include/c++/4.6/backward"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include"  -I"/usr/local/include"  -I"/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/include-fixed"  -I"/usr/include/x86_64-linux-gnu"  -I"/usr/include"  -I. -g -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread  -D__WX__ -w "/home/frozen/.codelite/clang_cache/main_cpp__H__.h" -emit-pch -o "/home/frozen/.codelite/clang_cache/main_cpp__H__.h.pch"
And this is the output:

Code: Select all

In file included from /home/frozen/.codelite/clang_cache/main_cpp__H__.h:1:
In file included from /usr/include/wx-2.8/wx/wx.h:16:
In file included from /usr/include/wx-2.8/wx/object.h:20:
In file included from /usr/include/wx-2.8/wx/memory.h:16:
In file included from /usr/include/wx-2.8/wx/string.h:176:
In file included from /usr/include/c++/4.6/string:41:
In file included from /usr/include/c++/4.6/bits/char_traits.h:40:
/usr/include/c++/4.6/bits/stl_algobase.h:378:43: error: unexpected type name '_ValueTypeI': expected expression
      const bool __simple = (__is_trivial(_ValueTypeI)
                                          ^
/usr/include/c++/4.6/bits/stl_algobase.h:383:40: error: non-type template argument of type 'const bool' is not an integral constant expression
      return std::__copy_move<_IsMove, __simple,
                                       ^~~~~~~~
/usr/include/c++/4.6/bits/stl_algobase.h:573:43: error: unexpected type name '_ValueType1': expected expression
      const bool __simple = (__is_trivial(_ValueType1)
                                          ^
/usr/include/c++/4.6/bits/stl_algobase.h:578:49: error: non-type template argument of type 'const bool' is not an integral constant expression
      return std::__copy_move_backward<_IsMove, __simple,
                                                ^~~~~~~~
/usr/include/c++/4.6/bits/stl_algobase.h:731:32: error: expected ';' in 'for' statement specifier
      for (__decltype(__n + 0) __niter = __n;
                               ^
/usr/include/c++/4.6/bits/stl_algobase.h:731:32: error: use of undeclared identifier '__niter'
/usr/include/c++/4.6/bits/stl_algobase.h:732:5: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
           ^
/usr/include/c++/4.6/bits/stl_algobase.h:732:16: error: expected ')'
           __niter > 0; --__niter, ++__first)
                      ^
/usr/include/c++/4.6/bits/stl_algobase.h:731:11: note: to match this '('
      for (__decltype(__n + 0) __niter = __n;
          ^
/usr/include/c++/4.6/bits/stl_algobase.h:732:20: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
                          ^
/usr/include/c++/4.6/bits/stl_algobase.h:743:32: error: expected ';' in 'for' statement specifier
      for (__decltype(__n + 0) __niter = __n;
                               ^
/usr/include/c++/4.6/bits/stl_algobase.h:743:32: error: use of undeclared identifier '__niter'
/usr/include/c++/4.6/bits/stl_algobase.h:744:5: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
           ^
/usr/include/c++/4.6/bits/stl_algobase.h:744:16: error: expected ')'
           __niter > 0; --__niter, ++__first)
                      ^
/usr/include/c++/4.6/bits/stl_algobase.h:743:11: note: to match this '('
      for (__decltype(__n + 0) __niter = __n;
          ^
/usr/include/c++/4.6/bits/stl_algobase.h:744:20: error: use of undeclared identifier '__niter'
           __niter > 0; --__niter, ++__first)
                          ^
14 errors generated.
Everything compiles fine, if I build the project (After taking out test. of course)...
See here:

Code: Select all

 ----------Build Started--------
/bin/sh -c '"make"  -j 4 -f "ccompletiontest_wsp.mk"'
----------Building project:[ ccompletiontest - Debug ]----------
make[1]: Entering directory `/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest'
make[1]: Leaving directory `/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest'
make[1]: Entering directory `/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest'
g++  -c  "/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest/main.cpp" -g -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread -D__WX__  -o ./Debug/main.o -I. 
g++ -o ./Debug/ccompletiontest ./Debug/main.o  -L.   -mwindows -pthread   -lwx_gtk2u_richtext-2.8 -lwx_gtk2u_aui-2.8 -lwx_gtk2u_xrc-2.8 -lwx_gtk2u_qa-2.8 -lwx_gtk2u_html-2.8 -lwx_gtk2u_adv-2.8 -lwx_gtk2u_core-2.8 -lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8 
make[1]: Leaving directory `/home/frozen/codelite_workspace/ccompletiontest/ccompletiontest'
----------Build Ended----------
0 errors, 0 warnings
I'm confused now..

Thanks again,

frozen
User avatar
eranif
CodeLite Plugin
Posts: 6146
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Trouble with code completion

Post by eranif »

No need to be confused :)

codelite invokes clang to create a PCH file to boost the completion time - the PCH file is then cached for later use.
However, seems like clang can not compile a simple file when using gcc's 4.6 include paths...

As a workaround:
If you could install gcc 4.5 along side 4.6 and point ctags / clang to its include paths - it will solve your problems (until I will fix the completion with gcc 4.6)
If you do decide to install gcc 4.5 along side 4.6 you can use the following method to obtain the list of the include paths from the compiler:

Code: Select all

touch /tmp/a.cpp
/path/to/gcc-4.5/cpp -x c++ -v /tmp/a.cpp
(make sure that you are using the gcc 4.5's cpp executable)

You could also (in the same logic) point ctags to use those paths - and it will work.

Eran
Make sure you have read the HOW TO POST thread
Post Reply