Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: Lalaland on November 10, 2011, 03:51:45 pm

Title: ClangComplete plugin
Post by: Lalaland on November 10, 2011, 03:51:45 pm
V 0.1 is now complete.

Compilation Instructions
For windows you will need "Clang Binaries for Mingw32/x86" at http://llvm.org/releases/download.html plus whatever it takes to normally compile plugins for codeblocks. You will need to add clang.dll, found in the bin folder and the include folder to the build options

For linux you will need a package that provides libclang.so, the debian package is libclang1.  You will also need the headers, which can be found in the debian libclang-dev package.


The github directory can be found here:
https://github.com/Lalaland/ClangComplete

Just click on downloads and download the zip file. In the zip file is the codeblocks project file + the source files.


Usage Instructions
Create a simple project and restart codeblocks.

Load the .cbplugin plugin.
Open the simple project.
When you type 3 letters of a word, '.', '->' or '::' , or press the keys Cntr-F1 codecompletion will start

Note, this plugin will probably fail on advanced projects(at least it fails on this project), just use it on simple stuff for now



I am announcing that I am starting work on an alternate code completion plugin that uses libclang to parse the code.

With very simplistic code I am starting out with this:
http://i.imgur.com/JAs6w.png

With some images and alphabetical sorting I am here:
(http://img839.imageshack.us/img839/760/blahua.th.png) (http://img839.imageshack.us/img839/760/blahua.png)

With correct accessibility images I am here:
(http://img210.imageshack.us/img210/6994/foonq.th.png) (http://img210.imageshack.us/img210/6994/foonq.png)

No more showing of things you cannot use:
(http://s12.postimage.org/dzushacyh/image.jpg) (http://postimage.org/image/dzushacyh/)

Code completion in the middle of words + local variables:
(http://i.imgur.com/LeNgjs.png) (http://imgur.com/LeNgj.png)
(http://i.imgur.com/YrLyFs.png) (http://imgur.com/YrLyF.png)


Goals for V1:

Now I need to move into providing auxillary features such as: calltip help, find declaration, etc

Current goals include:

Bugs

NOTE: I am no longer using a patched libclang
Title: Re: ClangComplete plugin
Post by: dmoore on November 10, 2011, 07:53:01 pm
Lalaland: libclang looks *VERY* powerful. That's a stunningly simple example.

A useful thing that could happen is for you to figure out a way of pulling out the common UI pieces that all CC plugins would share from the current C::B CC plugin (much like ObFuScAtEd is doing for the debugger).
Title: Re: ClangComplete plugin
Post by: dmoore on November 10, 2011, 08:11:23 pm
btw, is clang fast enough to parse the buffer on the fly, as in your simple example, or do you need to get clang to pre-scan all of the files in order to get acceptable responsiveness?
Title: Re: ClangComplete plugin
Post by: oBFusCATed on November 10, 2011, 10:47:25 pm
Yay, go on Lalaland, we are with you :)
Title: Re: ClangComplete plugin
Post by: ollydbg on November 11, 2011, 01:40:57 am
Great Job. I'm thinking what I can contribute :D.
It looks like you are directly link to "libclang", this is different with codelite's implementation (it call clang.exe from command line).

By the way, this topic should be moved to CodeCompletion redesign (http://forums.codeblocks.org/index.php/board,18.0.html), we have a sub-forum dedicated to CC, there I have some clang stuff posted some days ago.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 11, 2011, 05:27:41 am
odmoore: It does seem to lag a bit with a large number of includes. This
Code
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>
#include <boost/signal.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <boost/aligned_storage.hpp>
#include <boost/enable_shared_from_this.hpp>

for example adds about a 2 second delay.

However, by enabling some flags that supposedly create some sort of cache, it only has the long delay the first time code completion is requested.

All the rest of the requests complete almost instantaneously.

Thank you for pointing out codelite's implementation.
Title: Re: ClangComplete plugin
Post by: ollydbg on November 11, 2011, 05:47:07 am
However, by enabling some flags that supposedly create some sort of cache, it only has the long delay the first time code completion is requested.
All the rest of the requests complete almost instantaneously.
Once I have seen in the clang's API document, there is an function parameter which can let clang to automatically create a pch file in memory. Then the user don't need to specify which file are PCH file, clang can create and maintain the cached PCH.

The other thing is that we need to grab all the "compiler search paths" and "user definitions" from the current target in c::b project.
BTW: QTcreator now has a branch to use clang too.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 11, 2011, 06:59:28 am
I have already started looking into grabbing all of the search paths.
This code is what I am using to do it.
Code
            ProjectBuildTarget *target = Manager::Get()->GetProjectManager()->GetActiveProject()->GetBuildTarget(0);
            wxString test = target->GetCompilerID();
            Compiler * comp = CompilerFactory::GetCompiler(test);

            wxArrayString next = comp->GetCompilerSearchDirs(target);

            wxString pray = GetStringFromArray(next, _(" "));

            Manager::Get()->GetLogManager()->Log(pray);

However, I have not looked into user definitions and other command line settings yet.
I just wish the documentation on the Compiler::GenerateCommandLine function was better.

EDIT: I got the GenerateCommandLine function working(just copied the code found in the compiler plugin)
Title: Re: ClangComplete plugin
Post by: rickg22 on November 11, 2011, 07:27:53 am
odmoore: It does seem to lag a bit with a large number of includes. This
Code
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>
#include <boost/signal.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <boost/aligned_storage.hpp>
#include <boost/enable_shared_from_this.hpp>


Okay, I'm getting a bit paranoid with boost. Last time I tried to install boost, my distro screwed up the dependencies.
Title: Re: ClangComplete plugin
Post by: MortenMacFly on November 11, 2011, 08:16:21 am
I am announcing that I am starting work on an alternate code completion plugin that uses libclang to parse the code.
It looks very promising. One note: Please keep in mind that the plugin should derive from cbCodeCompletionPlugin, not cbPlugin to work properly in the end.
Title: Re: ClangComplete plugin
Post by: daniloz on November 11, 2011, 08:19:29 am
Hey this really looks great and promising...

I've tried to compile it on Windows and had to change some project definitions, maybe I can contribute with a windows version of the project file (as soon as I get it running here).

However, I could not yet compile the libclang... So, here my questions:

- is there a precompiled libclang.dll for windows already somewhere ?
- any directions of how to compile it? :-)
Title: Re: ClangComplete plugin
Post by: MortenMacFly on November 11, 2011, 08:35:41 am
- any directions of how to compile it? :-)
http://clang.llvm.org/get_started.html
Title: Re: ClangComplete plugin
Post by: ollydbg on November 11, 2011, 08:54:36 am
- is there a precompiled libclang.dll for windows already somewhere ?
- any directions of how to compile it? :-)
We have discussed this on the forum.
You can use either CMake+mingw or Cmake+VC or MSYS+mingw.
see:Re: Clang command line support for codecompletion (http://forums.codeblocks.org/index.php/topic,13559.msg91417.html#msg91417) and the following posts. :D

@
Lalaland
I'm not sure how you collect the GCC/MSVC's default compiler paths, for GCC, I know this is a function in CC to collect those paths, see:

Code
const wxArrayString& NativeParser::GetGCCCompilerDirs(const wxString &cpp_compiler)
{
    // keep the gcc compiler path's once if found across C::B session
    // makes opening workspaces a *lot* faster by avoiding endless calls to the compiler
    static std::map<wxString, wxArrayString> dirs;
    if (!dirs[cpp_compiler].IsEmpty())
        return dirs[cpp_compiler];

    // for starters , only do this for gnu compiler
    //CCLogger::Get()->DebugLog(_T("CompilerID ") + CompilerID);
    //
    //   Windows: mingw32-g++ -v -E -x c++ nul
    //   Linux  : g++ -v -E -x c++ /dev/null
    // do the trick only for c++, not needed then for C (since this is a subset of C++)


    // let's construct the command
    // use a null file handler
    // both works fine in Windows and Linux

#ifdef __WXMSW__
    wxString Command = cpp_compiler + _T(" -v -E -x c++ nul");
#else
    wxString Command = cpp_compiler + _T(" -v -E -x c++ /dev/null");
#endif

    // wxExecute can be a long action and C::B might have been shutdown in the meantime...
    if (Manager::IsAppShuttingDown())
        return dirs[cpp_compiler];

    static bool flag = false;
    if (flag)
        return dirs[cpp_compiler];

    // action time  (everything shows up on the error stream
    wxArrayString Output, Errors;
    flag = true;
    if (wxExecute(Command, Output, Errors, wxEXEC_SYNC | wxEXEC_NODISABLE) == -1)
    {
        TRACE(_T("GetGCCCompilerDirs::wxExecute failed!"));
        flag = false;
        return dirs[cpp_compiler];
    }
    flag = false;

    // start from "#include <...>", and the path followed
    // let's hope this does not change too quickly, otherwise we need
    // to adjust our search code (for several versions ...)
    bool start = false;
    for (size_t idxCount = 0; idxCount < Errors.GetCount(); ++idxCount)
    {
        wxString path = Errors[idxCount].Trim(true).Trim(false);
        if (!start)
        {
            if (!path.StartsWith(_T("#include <...>")))
                continue;
            path = Errors[++idxCount].Trim(true).Trim(false);
            start = true;
        }

        wxFileName fname(path, wxEmptyString);
        fname.Normalize();
        fname.SetVolume(fname.GetVolume().MakeUpper());
        if (!fname.DirExists())
            break;

        CCLogger::Get()->DebugLog(_T("Caching GCC dir: ") + fname.GetPath());
        dirs[cpp_compiler].Add(fname.GetPath());
    }

    return dirs[cpp_compiler];
}

void NativeParser::AddGCCCompilerDirs(Compiler* compiler, ParserBase* parser)
{
    wxFileName fn(wxEmptyString, compiler->GetPrograms().CPP);
    wxString masterPath = compiler->GetMasterPath();
    Manager::Get()->GetMacrosManager()->ReplaceMacros(masterPath);
    fn.SetPath(masterPath);
    fn.AppendDir(_T("bin"));

    const wxArrayString& gccDirs = GetGCCCompilerDirs(fn.GetFullPath());
    TRACE(_T("Adding %d cached gcc dirs to parser..."), gccDirs.GetCount());
    for (size_t i=0; i<gccDirs.GetCount(); ++i)
    {
        parser->AddIncludeDir(gccDirs[i]);
        TRACE(_T("AddCompilerDirs() : Adding cached compiler dir to parser: ") + gccDirs[i]);
    }
}
Title: Re: ClangComplete plugin
Post by: Lalaland on November 11, 2011, 05:25:39 pm
Hey this really looks great and promising...

I've tried to compile it on Windows and had to change some project definitions, maybe I can contribute with a windows version of the project file (as soon as I get it running here).

However, I could not yet compile the libclang... So, here my questions:

- is there a precompiled libclang.dll for windows already somewhere ?
- any directions of how to compile it? :-)

If you are in linux, sudo apt-get install libclang does the trick. I do not know for windows.

@
Lalaland
I'm not sure how you collect the GCC/MSVC's default compiler paths, for GCC, I know this is a function in CC to collect those paths, see:


I am using this (almost a direct copy and paste from the gcc compiler plugin)

         
Code
  ProjectFile* pf = editor->GetProjectFile();
            ProjectBuildTarget *target = Manager::Get()->GetProjectManager()->GetActiveProject()->GetBuildTarget(0);
            wxString test = target->GetCompilerID();
            Compiler * comp = CompilerFactory::GetCompiler(test);

            const pfDetails& pfd = pf->GetFileDetails(target);


            wxString Object = (comp->GetSwitches().UseFlatObjects)?pfd.object_file_flat:pfd.object_file;

            const CompilerTool &tool = comp->GetCompilerTool(ctCompileObjectCmd,_(".cpp"));
            wxString tempCommand = _("$options $includes");
            comp->GenerateCommandLine(tempCommand,target,pf,UnixFilename(pfd.source_file_absolute_native),Object,pfd.object_file_flat,
                                         pfd.dep_file);




            Manager::Get()->GetLogManager()->Log(tempCommand);

Which seems to work works, and has given me this for my current project.
Code
 -g -I/usr/include/codeblocks -I/usr/include/codeblocks/tinyxml -I/usr/include/codeblocks/scripting/include -I/usr/include/codeblocks/scripting/bindings -I/usr/include/codeblocks/scripting/sqplus -I/usr/include/codeblocks/wxscintilla/include    -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  -fPIC    -I../../../../usr/include/codeblocks 
So this problem appears to be solved(however,  the GenerateCommandLine functions should be refactored. Instead of all those ending arguments it should just take a pfDetails, or just a ProjectFile)
Title: Re: ClangComplete plugin
Post by: Lalaland on November 11, 2011, 06:10:58 pm
I finally have an improvement over the official version of code completion.
The current code completion cannot handle the macro mess also known as wx/buffer.h, so it cannot complete wxCharBuffer.

However, clang has no problem completing it :)
(http://img27.imageshack.us/img27/2483/blahu.th.png) (http://img27.imageshack.us/img27/2483/blahu.png)

Title: Re: ClangComplete plugin
Post by: ollydbg on November 12, 2011, 02:07:24 am
I mean how clang can find the gcc's default search paths, different version of gcc has different paths, like:

Code
Caching GCC dir: E:\code\cb\gcc\mingw-static-4.4.5-all\lib\gcc\i686-mingw32\4.4.5\include\c++
Caching GCC dir: E:\code\cb\gcc\mingw-static-4.4.5-all\lib\gcc\i686-mingw32\4.4.5\include\c++\i686-mingw32
Caching GCC dir: E:\code\cb\gcc\mingw-static-4.4.5-all\lib\gcc\i686-mingw32\4.4.5\include\c++\backward
Caching GCC dir: E:\code\cb\gcc\mingw-static-4.4.5-all\include
Caching GCC dir: E:\code\cb\gcc\mingw-static-4.4.5-all\lib\gcc\i686-mingw32\4.4.5\include
Caching GCC dir: E:\code\cb\gcc\mingw-static-4.4.5-all\lib\gcc\i686-mingw32\4.4.5\include-fixed

Does clang has it's own include files so that we do not need mingw's ?
Title: Re: ClangComplete plugin
Post by: Lalaland on November 12, 2011, 07:46:13 am
No, you are right, it is using gcc's search directories.

It seems that it can search a limited number of hardcoded paths for the headers(there is a whole complex module for this, tons of switch statements and  "// FIXME: temporary hack: hard-coded paths.") , eg
Code
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");

which is why it seems to work, but I actually need to find the real paths to get it working when Mingw is not installed in the usual locations ...
Title: Re: ClangComplete plugin
Post by: Lalaland on November 14, 2011, 07:57:54 am
How does codeblocks filter results completions that are not related to a container(Ie, does not '->', '.' or '::')
With no container, you get hundreds of possible completions.

Should I filter and show only variables, only functions, ?
Showing all possible completions causes observable delays, and the resulting list is too large to use.

Also:
How useful is it to users to have the icon also show accesability(private, protected, etc)?
While it is possible with clang(the functions are there) it seems that I would have parse the file twice in order to get this kind of type information.
Title: Re: ClangComplete plugin
Post by: ollydbg on November 14, 2011, 08:27:33 am
How does codeblocks filter results completions that are not related to a container(Ie, does not '->', '.' or '::')
With no container, you get hundreds of possible completions.
You mean the current implementation in Codeblocks? As far as I know, it dose not filter any thing, but note that the "auto-completion" should be only triggered by:
1, after "->", "::" or "."
2, after user continuously entered four characters, so we do a prefix match of four chars, and only list the tokens which have the same prefix string. note: the value "four" can be configured to "two" or even "one", which means more Tokens will be listed, but we have a limit value (like 10000).
3, when the user continuously enter some more characters, we just use the result in the step 2.

Quote
Should I filter and show only variables, only functions, ?
Showing all possible completions causes observable delays, and the resulting list is too large to use.
The best way is show automatic variable firstly, and then class members, then global variables....So, I think the Tokens from clang should be sorted. :D

Quote
Also:
How useful is it to users to have the icon also show accesability(private, protected, etc)?
While it is possible with clang(the functions are there) it seems that I would have parse the file twice in order to get this kind of type information.
Yeah, this is much better!
Title: Re: ClangComplete plugin
Post by: Folco on November 15, 2011, 09:15:43 pm
My personal opinion : I don't use these pictures. The names I choose are explicit, and I never learned the meaning of these symbols.
Title: Re: ClangComplete plugin
Post by: ollydbg on November 16, 2011, 01:06:39 am
My personal opinion : I don't use these pictures. The names I choose are explicit, and I never learned the meaning of these symbols.
You are answering to this question below?
Quote
How useful is it to users to have the icon also show accesability(private, protected, etc)?
Title: Re: ClangComplete plugin
Post by: Lalaland on November 16, 2011, 08:11:05 am
Regardless, I have added the icons for visibility.

(http://img210.imageshack.us/img210/6994/foonq.th.png) (http://img210.imageshack.us/img210/6994/foonq.png)

The only issue is that I had to modify libclang slightly to do it.
I have submitted a patch request, but until then, I have attached the patch to this post.

Now the only main issue is to work on handling code completion with no context.
Title: Re: ClangComplete plugin
Post by: Folco on November 16, 2011, 05:55:11 pm
My personal opinion : I don't use these pictures. The names I choose are explicit, and I never learned the meaning of these symbols.
You are answering to this question below?
Quote
How useful is it to users to have the icon also show accesability(private, protected, etc)?

Yes I do.

Could these pictures be optional ?
Title: Re: ClangComplete plugin
Post by: daniloz on November 16, 2011, 10:57:36 pm
Could these pictures be optional ?

Come on... Even if you don't use the pictures (which I do a lot), they are very unlikely to disturb anyone, right? ;-)

Anyway, even if "the names [you] choose are explicit", you still have do deal with code from others, like your beloved CodeBlocks API/SDK, for example, right? And then, the pictures really help me a lot!!!!

Just my 2 cents, though...
Title: Re: ClangComplete plugin
Post by: Lalaland on November 17, 2011, 01:00:43 am
I am just going to keep the pictures in there.
Right now the major goal of this plugin is to mirror the experience but provide better functionality than the current plugin.
And, those pictures are a major part of the "experience".
Title: Re: ClangComplete plugin
Post by: ollydbg on November 17, 2011, 01:58:45 pm
It looks like the codelite IDE was changing its way to call clang, see its svn chang log:
Quote
Revision: 5276
Author: eranif
Date: 2011-11-17 15:12:47
Message:
added clang sdk for Windows
-------------------------------
A : /trunk/sdk/clang

A : /trunk/sdk/clang/include

A : /trunk/sdk/clang/include/clang-c

A : /trunk/sdk/clang/include/clang-c/Index.h

A : /trunk/sdk/clang/lib

A : /trunk/sdk/clang/lib/clang.dll


Now, it will depend on clang shared library.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 18, 2011, 06:54:17 am
Clang allows you to see what is accessible.
Should I hide non-accessible results?
Title: Re: ClangComplete plugin
Post by: ollydbg on November 18, 2011, 06:58:29 am
Clang allows you to see what is accessible.
Should I hide non-accessible results?
I think "non-accessible results" should be hide in the completion suggest list. :D

The other question is: (dependency question)
If some would like to distribute this clangcompletion plugin, which file should be included.
The clangcompletion dll
and the clang.dll
Or other files needed?
Title: Re: ClangComplete plugin
Post by: Lalaland on November 18, 2011, 07:15:31 am
Well I use the images from the real code completion plugin.
Title: Re: ClangComplete plugin
Post by: MortenMacFly on November 18, 2011, 07:41:57 am
Remember:
One note: Please keep in mind that the plugin should derive from cbCodeCompletionPlugin, not cbPlugin to work properly in the end.
I would recommend you better do it before it's too late and requires massive re-factoring. In the end the interface of cbPlugin (wrong for a CC plugin) and cbCodeCompletionPlugin is different.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 18, 2011, 07:52:18 am
Couple of improvements.

No more showing of things you cannot use:
(ClangComplete)
(http://s12.postimage.org/dzushacyh/image.jpg) (http://postimage.org/image/dzushacyh/)

(Code Complete)
(http://s11.postimage.org/rr9tx3vgv/st1.png) (http://postimage.org/image/rr9tx3vgv/)


I also finally started sorting by libclang's "priority". Objects are sorted by priority first, and then by alphabetical order.
Summary, junk(such as definitions) floats to the bottom, but the usefull things (such as methods and members) are alphabetically sorted as you would expect.
(http://s11.postimage.org/hv8qxgpov/st2.png) (http://postimage.org/image/hv8qxgpov/)

The plugin is also now derived from cbCodeCompletionPlugin, but that does not do much as only the CodeComplete function does something.

EDIT: I have now also hidden everything starting with an '_'. Those internals should not be used anyways.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 19, 2011, 01:29:48 am
I am having an issue. The code completion dialog will not show up when called in the middle of a word.
I am using the same code as the official plugin to generate the location for the code completion.

Code
    int pos   = control->GetCurrentPos();
    int start = control->WordStartPosition(pos, true);
    wxString final = GetStringFromArray(items, _(" "));

    control->AutoCompSetCancelAtStart(false);
    control->AutoCompSetAutoHide(true);

    control->AutoCompShow(pos-start,final );

Items is an array of the completions.

The following shows how it works with no letters, and then fails when trying to complete with at least one.

(I have posted so many pictures that I might as well try a video now)
http://youtu.be/AjbFL_n0qos

This is the only work left to completing in the middle of the word.

Title: Re: ClangComplete plugin
Post by: Alpha on November 19, 2011, 03:14:40 am
My personal opinion : I don't use these pictures. The names I choose are explicit, and I never learned the meaning of these symbols.
If you were wondering, I have added a table defining these symbols to the Code Completion plugin (http://wiki.codeblocks.org/index.php?title=Code_Completion_plugin) wiki-page.

@Lalaland: I am afraid I do not yet know enough about the process of code completion to help you, however, I did want to say: good job so far.
Title: Re: ClangComplete plugin
Post by: ollydbg on November 19, 2011, 05:01:10 am
My personal opinion : I don't use these pictures. The names I choose are explicit, and I never learned the meaning of these symbols.
If you were wondering, I have added a table defining these symbols to the Code Completion plugin (http://wiki.codeblocks.org/index.php?title=Code_Completion_plugin) wiki-page.
This table is quite good, nice work!!!

Quote
@Lalaland: I am afraid I do not yet know enough about the process of code completion to help you, however, I did want to say: good job so far.
I will try to give some help :D
Title: Re: ClangComplete plugin
Post by: ollydbg on November 19, 2011, 05:59:42 am
If you set a breakpoint in the function body: NativeParser::AI

You will get the call stack when you enter some chars in the middle of a word.
Code
> bt 30
#0  NativeParser::AI (this=0x3bf6040, result=std::set with 0 elements, searchData=0x22ed28, lineText="", isPrefix=true, caseSensitive=false, search_scope=0x22ecb8, caretPos=-1) at e:\code\cb\cb_trunk\src\plugins\codecompletion\nativeparser.cpp:2338
#1  0x65ec4ae1 in NativeParser::MarkItemsByAI (this=0x3bf6040, searchData=0x22ed28, result=std::set with 0 elements, reallyUseAI=true, isPrefix=true, caseSensitive=false, caretPos=-1) at e:\code\cb\cb_trunk\src\plugins\codecompletion\nativeparser.cpp:1745
#2  0x65ec47f9 in NativeParser::MarkItemsByAI (this=0x3bf6040, result=std::set with 0 elements, reallyUseAI=true, isPrefix=true, caseSensitive=false, caretPos=-1) at e:\code\cb\cb_trunk\src\plugins\codecompletion\nativeparser.cpp:1690
#3  0x65ea7554 in CodeCompletion::CodeComplete (this=0x3bf5ff8) at e:\code\cb\cb_trunk\src\plugins\codecompletion\codecompletion.cpp:1042
#4  0x65eac167 in CodeCompletion::DoCodeComplete (this=0x3bf5ff8) at e:\code\cb\cb_trunk\src\plugins\codecompletion\codecompletion.cpp:1776
#5  0x65eb2935 in CodeCompletion::EditorEventHook (this=0x3bf5ff8, editor=0x5685008, event=...) at e:\code\cb\cb_trunk\src\plugins\codecompletion\codecompletion.cpp:3346
#6  0x65f0958d in EditorHooks::HookFunctor<CodeCompletion>::Call (this=0x2f2e480, editor=0x5685008, event=...) at e:\code\cb\cb_trunk\src\include\editor_hooks.h:54
#7  0x00a943d1 in EditorHooks::CallHooks (editor=0x5685008, event=...) at e:\code\cb\cb_trunk\src\sdk\editor_hooks.cpp:60
#8  0x00a5a353 in cbEditor::OnScintillaEvent (this=0x5685008, event=...) at e:\code\cb\cb_trunk\src\sdk\cbeditor.cpp:3554
#9  0x00a59a67 in cbEditor::OnEditorCharAdded (this=0x5685008, event=...) at e:\code\cb\cb_trunk\src\sdk\cbeditor.cpp:3362
#10 0x627720b6 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#11 0x62772520 in wxEvtHandler::SearchDynamicEventTable(wxEvent&) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#12 0x627725d3 in wxEvtHandler::ProcessEvent(wxEvent&) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#13 0x6285b59d in wxWindowBase::TryParent(wxEvent&) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#14 0x00b72642 in wxScintilla::NotifyParent (this=0x56af358, _scn=0x22f31c) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\wxscintilla.cpp:5084
#15 0x00b752dc in ScintillaWX::NotifyParent (this=0x56ae008, scn=...) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\ScintillaWX.cpp:521
#16 0x00bf287c in Editor::NotifyChar (this=0x56ae008, ch=67) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\scintilla\src\Editor.cxx:4377
#17 0x00bf0cc8 in Editor::AddCharUTF (this=0x56ae008, s=0x55ca288 "C", len=1, treatAsDBCS=false) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\scintilla\src\Editor.cxx:4081
#18 0x00c05a49 in ScintillaBase::AddCharUTF (this=0x56ae008, s=0x55ca288 "C", len=1, treatAsDBCS=false) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\scintilla\src\ScintillaBase.cxx:76
#19 0x00b76da3 in ScintillaWX::DoAddChar (this=0x56ae008, key=67) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\ScintillaWX.cpp:1067
#20 0x00b71b67 in wxScintilla::OnChar (this=0x56af358, evt=...) at e:\code\cb\cb_trunk\src\sdk\wxscintilla\src\wxscintilla.cpp:4811
#21 0x627720b6 in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#22 0x6277222a in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#23 0x627725f6 in wxEvtHandler::ProcessEvent(wxEvent&) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#24 0x627b2c93 in wxWindow::HandleChar(unsigned int, long, bool) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#25 0x627b471a in wxWindow::MSWWindowProc(unsigned int, unsigned int, long) () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#26 0x627af438 in wxWndProc () from E:\code\cb\wx\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
#27 0x7e418734 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
#28 0x000503b6 in ?? ()
warning: (Internal error: pc 0x101 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x101 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x101 in read in psymtab, but not in symtab.)
warning: (Internal error: pc 0x101 in read in psymtab, but not in symtab.)
#29 0x00000102 in ?? ()
>>>>>>cb_gdb:

So, You can see in the AI's body:

Code
    int pos = caretPos == -1 ? searchData->control->GetCurrentPos() : caretPos;
    if (pos < 0 || pos > searchData->control->GetLength())
        return 0;

    m_EditorStartWord = searchData->control->WordStartPosition(pos, true);
    m_EditorEndWord   = pos; //editor->GetControl()->WordEndPosition(pos, true);
    int line = searchData->control->LineFromPosition(pos);

    // Get the actual search text, such as "objA.m_aaa.m_bbb"
    wxString actual_search(lineText);
    if (actual_search.IsEmpty())
    {
        // Get the position at the start of current line
        const int startPos = searchData->control->PositionFromLine(line);
        actual_search = searchData->control->GetTextRange(startPos, pos).Trim();
    }

Note, the actual_search is the current line Text you might interests.

PS: I'm debugging the c::b's trunk code.
Title: Re: ClangComplete plugin
Post by: Folco on November 19, 2011, 02:54:35 pm
Nice job and thanks Alpha. :)

Lalaland -> these pictures are not a "major part of the experience" for me. I humbly apologise to have another opinion than yours.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 19, 2011, 03:16:14 pm
Folco: It is fine, I will add the idea of providing an option to disable the images to the todo list.

ollydbg: Good idea to step through it with a debugger, I can not believe that I did not think of that first.
Title: Re: ClangComplete plugin
Post by: Folco on November 19, 2011, 03:59:23 pm
Thanks for that. And congrats for doing such a plugin, it's obviously a huge work.
Title: Re: ClangComplete plugin
Post by: Alpha on November 19, 2011, 07:51:49 pm
This table is quite good, nice work!!!
Nice job and thanks Alpha. :)
:)

@Lalaland: I have a feature suggestion/request; assuming Clang reports whenever/wherever there is a parsing error, would it be possible for the ClangComplete plugin to put a red marker by the line(s) with errors, or underline (like spell-check) the specific token the error occurs in?
Title: Re: ClangComplete plugin
Post by: Lalaland on November 20, 2011, 04:14:59 am
Quote
@Lalaland: I have a feature suggestion/request; assuming Clang reports whenever/wherever there is a parsing error, would it be possible for the ClangComplete plugin to put a red marker by the line(s) with errors, or underline (like spell-check) the specific token the error occurs in?

Feature requesting is a little premature, I have to get the plugin working first.

God, this issue of the menu not popping up in the middle of the word is getting stranger and stranger. The actual issue seems to be that wxScintilla thinks that the word is not being matched(and this is for code completion at the start as well). At the same time, other random words(such as double or class) seem to work. And what really is strange is that the words which works changes determining on where you do the completion.


Here is a video showing what is happening. I turned off autohide, so you can see how wxScintilla does not think anything is matched. I am also using a keyboard shortcut to start autocompletion.

What you will see in this video is me typing in the starts of some keywords that appear in the list of valid completions, and the list correctly moving and highlighting the entry. If it does not do this, then it thinks the word is not in the list, and the list would usually close.
http://youtu.be/kAjb2RwxGqg
(The text at the bottom is showing the string I am passing to show, with '|' set as the separator)

I also double checked the length of the strings churned out by clang. They are the right length as both cstrings and wxStrings, and seem to be fine when printed out(I even tried removing the first character by increasing the cstring by 1, and that worked as expected).

Following the debugger showed that I am putting the right value for the distance to the start of the word, so that is obviously not the issue.

I am truly stumped.
Does anyone have any clue about what is happening?
Title: Re: ClangComplete plugin
Post by: Alpha on November 20, 2011, 05:43:54 am
Feature requesting is a little premature, I have to get the plugin working first.
You are right, I am quite early, sorry (although, it is sometimes hard to be patient... I will try to save these for later :)).
Title: Re: ClangComplete plugin
Post by: ollydbg on November 20, 2011, 05:48:56 am
Quote
@Lalaland: I have a feature suggestion/request; assuming Clang reports whenever/wherever there is a parsing error, would it be possible for the ClangComplete plugin to put a red marker by the line(s) with errors, or underline (like spell-check) the specific token the error occurs in?

Feature requesting is a little premature, I have to get the plugin working first.

God, this issue of the menu not popping up in the middle of the word is getting stranger and stranger. The actual issue seems to be that wxScintilla thinks that the word is not being matched(and this is for code completion at the start as well). At the same time, other random words(such as double or class) seem to work. And what really is strange is that the words which works changes determining on where you do the completion.


Here is a video showing what is happening. I turned off autohide, so you can see how wxScintilla does not think anything is matched. I am also using a keyboard shortcut to start autocompletion.
http://youtu.be/kAjb2RwxGqg
(The text at the bottom is showing the string I am passing to show, with '|' set as the separator)

I also double checked the length of the strings churned out by clang. They are the right length as both cstrings and wxStrings, and seem to be fine when printed out(I even tried removing the first character by increasing the cstring by 1, and that worked as expected).

Following the debugger showed that I am putting the right value for the distance to the start of the word, so that is obviously not the issue.

I am truly stumped.
Does anyone have any clue about what is happening?

I have watch your video two times, but I have no idea what's your problem is........ :(

Edit:
I have see that you get code completion in comments?
You can simply filter it out, some code like:
Code

            // skip string or comment
            const int style = control->GetStyleAt(Your_osition);
            if (control->IsString(style) || control->IsComment(style))
            {
                 do some thing;
            }
Title: Re: ClangComplete plugin
Post by: Lalaland on November 20, 2011, 06:11:32 am
All of those words I type in(double , struct, class) etc should cause the menu to jump to and highlight the right entry.
Normally, when it does not work, the dialog simply goes away. I just set the setting that makes the codecompletion list stay, but show no highlighted entry.

Notice the failed attempts at typing in double and char the first time, despite them being clearly visible in the list.
Struct does work, and you can see it jump and highlight the right entry.

Then, when I switch to another location, typing in the start of "double" immediately jumps to the double keyword, and struct fails to work.

This is what causes my codecompletion inside a word to seem to fail, it is correctly creating the list, but it believes there are no matches for that start of the word and hides the list immediately(when I have the normal autohide setting enabled).

EDIT: You are right, only things typed in the default style should be auto-completed. I just added that now. Exceptions can be added as they are found.
Title: Re: ClangComplete plugin
Post by: ollydbg on November 20, 2011, 09:30:31 am
I'm not sure what is the logic you show the auto completion list.
Edit:Oh, I see you use the similar code: https://github.com/Lalaland/ClangComplete/blob/master/ClangComplete.cpp
Code
clang_disposeCodeCompleteResults(results);
    wxString final = GetStringFromArray(items, _("|"));
    final.RemoveLast();



    //control->CallTipShow(control->GetCurrentPos(), _("This is confusing"));
    control->AutoCompSetIgnoreCase(true);
    control->AutoCompSetCancelAtStart(false);
    control->AutoCompSetAutoHide(false);
    control->AutoCompSetSeparator('|');
    control->AutoCompStops(_(""));
   // final.RemoveLast();

//final = _("Hello boo");
    control->AutoCompShow(pos-start,final );
    wxString nums = _("pos: ");
    nums<<pos ;
    nums<<_(" start:");
    nums<<start;
     Manager::Get()->GetLogManager()->Log(final);

    return 0;


I just have a look at the current Codecompletion plugin's source code, see:

codecompletion.cpp line 1167.

Code
            ed->GetControl()->AutoCompSetIgnoreCase(!caseSens);
            ed->GetControl()->AutoCompSetCancelAtStart(true);
            ed->GetControl()->AutoCompSetFillUps(m_CCFillupChars);
            ed->GetControl()->AutoCompSetChooseSingle(m_IsAutoPopup ? false : m_CCAutoSelectOne);
            ed->GetControl()->AutoCompSetAutoHide(true);
            ed->GetControl()->AutoCompSetDropRestOfWord(m_IsAutoPopup ? false : true);
            wxString final = GetStringFromArray(items, _T(" "));
            final.RemoveLast(); // remove last space

            ed->GetControl()->AutoCompShow(pos - start, final);
            return 0;
        }

You see:
the items were the collected tokens strings. and the most important call is:
Code
ed->GetControl()->AutoCompShow(pos - start, final);

This will do what you would like in your clang code completion.
see its declaration:
Code
    // Display a auto-completion list.
    // The lenEntered parameter indicates how many characters before
    // the caret should be used to provide context.
    void AutoCompShow(int lenEntered, const wxString& itemList);

Hope this helps. :D

Edit:
This is the sample code I used to test CC:
Code
int abcd111;
int abcd212;
int abcd213;
int abcd414;
int abcd515;

abcd
Title: Re: ClangComplete plugin
Post by: Lalaland on November 22, 2011, 09:45:46 pm
God, the problem is solved. AutoCompShow needs the passed strings to be alphabetically sorted.
This fails because I sort my strings by priority.

Oh well, at least autocomplete in the middle of words works reliably now. I will post some pictures of this soon.

EDIT: And can we please add this to the doc

This ↓ tells me nothing about any sorting.
Code
    // Display a auto-completion list.
    // The lenEntered parameter indicates how many characters before
    // the caret should be used to provide context.
Title: Re: ClangComplete plugin
Post by: Lalaland on November 22, 2011, 11:08:55 pm
As promised, here are some pictures(I wanted to refactor the code first):

(http://i.imgur.com/LeNgjs.png) (http://imgur.com/LeNgj.png)

And this is the same code that the current code completion could not handle
(http://i.imgur.com/YrLyFs.png) (http://imgur.com/YrLyF.png)

EDIT: I am now also using the previously suggested code for manually adding in gcc's search paths.
Title: Re: ClangComplete plugin
Post by: ollydbg on November 23, 2011, 01:48:07 am
As promised, here are some pictures(I wanted to refactor the code first):

(http://i.imgur.com/LeNgjs.png) (http://imgur.com/LeNgj.png)

And this is the same code that the current code completion could not handle
(http://i.imgur.com/YrLyFs.png) (http://imgur.com/YrLyF.png)

EDIT: I am now also using the previously suggested code for manually adding in gcc's search paths.
Wonderful job!
I will take time to check it works under Windows+mingw. :D
Title: Re: ClangComplete plugin
Post by: ollydbg on November 23, 2011, 03:09:22 am
Hi, found another clang plugin:
A Small Matter of Programming: A Vim plugin for navigating C++ with libclang (http://blog.wuwon.id.au/2011/10/vim-plugin-for-navigating-c-with.html)

which can navigate in C++ source code. :D :D :D

Edit:
Another one:
https://github.com/jessevdk/gedit-code-assistance
Title: Re: ClangComplete plugin
Post by: Lalaland on November 23, 2011, 06:45:26 am
I now have actual file control, with a calltip if the file is not done yet. I am using a map of translation units to filenames, and it tries to compile all of the files in a project on project load.

That was the last goal on the list, so it is going to be time to make a new list of stuff to do ...

Sadly I am going to have to ditch accessablity, no-one replied to my email on the clang mailing list, and I want to be able to use the official precompiled libclang libraries.
Title: Re: ClangComplete plugin
Post by: Apxont on December 02, 2011, 07:07:27 pm
Is possible to save all clang trans units to cache, and then recreate them from cache without reparsing them from files by standart methods, or recreation must be implemented by programmer?
Title: Re: ClangComplete plugin
Post by: Lalaland on December 03, 2011, 07:12:44 am
According to the API, clang should be caching it's results for individual translation units. I am also holding onto translation units for files.
Title: Re: ClangComplete plugin
Post by: dmoore on September 30, 2012, 04:57:00 am
Has anyone successfully used this plugin recently?

I managed to build it on linux after fixing some weird includes, but so far trying to run i either get segfaults or a completion tip that says it is still parsing. Any tips?