#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>
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.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.
All the rest of the requests complete almost instantaneously.
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);
odmoore: It does seem to lag a bit with a large number of includes. ThisCode#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>
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.
- any directions of how to compile it? :-)http://clang.llvm.org/get_started.html
- is there a precompiled libclang.dll for windows already somewhere ?We have discussed this on the forum.
- any directions of how to compile it? :-)
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]);
}
}
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? :-)
@
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:
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);
-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
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
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");
How does codeblocks filter results completions that are not related to a container(Ie, does not '->', '.' or '::')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:
With no container, you get hundreds of possible completions.
Should I filter and show only variables, only functions, ?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
Showing all possible completions causes observable delays, and the resulting list is too large to use.
Also:Yeah, this is much better!
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.
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?
How useful is it to users to have the icon also show accesability(private, protected, etc)?
Yes I do.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?QuoteHow useful is it to users to have the icon also show accesability(private, protected, etc)?
Could these pictures be optional ?
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
Clang allows you to see what is accessible.I think "non-accessible results" should be hide in the completion suggest list. :D
Should I hide non-accessible results?
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.
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 );
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!!!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.I will try to give some help :D
> 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:
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();
}
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?
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 :)).
I have watch your video two times, but I have no idea what's your problem is........ :(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?
// skip string or comment
const int style = control->GetStyleAt(Your_osition);
if (control->IsString(style) || control->IsComment(style))
{
do some thing;
}
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;
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;
}
ed->GetControl()->AutoCompShow(pos - start, final);
// 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);
int abcd111;
int abcd212;
int abcd213;
int abcd414;
int abcd515;
abcd
// Display a auto-completion list.
// The lenEntered parameter indicates how many characters before
// the caret should be used to provide context.
As promised, here are some pictures(I wanted to refactor the code first):Wonderful job!
(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.