Hi,
I have updated the sample program on my website, it is now demonstrates the following:
1. Building up a GUI tree (AKA Symbol tree) using ctags & sqlite
2. GUI tree is updated upon saving the file. If you will change file content the tree will be updated once you save it, this is done since ctags accepts files as input, so updating the tree per interval is too much overhead (creating temporary file, passing it to ctags and then delete it - too much)
3. Saving the tree into database for later reloading
4. word completion is now completed - what is word completion you may ask, well, word completion is step one of the CodeCompletion, it completes words using Ctrl + Space, the completion is considering the local scope and the entire workspace.
HOw does it works? first it scans local scope for members that qualifies with the partial name under the cursor, and then scan the database and adds other matches (if we are inside class, it will add its members / functions) such as GLOBAL variables + function + class struct etc
if only single match exist, it will automatically insert it under the cursor, else it will print out to the debug window the matches it found. scope depth is taking into consideration as well, for example:
void foo()
{
int number =0;
if(number == 0)
{
wxString name;
break;
}
n<------ Here you type Ctrl + Space
only number will be available from local scope since name is in depth=2 while number is depth=1 same as n.
If you would like to check out the sample (I named the libe CodeLite & the sample program LiteEditor :wink::
http://www.eistware.com/wxes/codeparser/liteeditor.exe (http://www.eistware.com/wxes/codeparser/liteeditor.exe)
If you want the source files, drop me a message here or in private and I will upload them or email them (to package them I need to close my editor and close all windows so I can tar it ^^)
Eran
Hi,
I think that the code completion is pretty much ready for integration - if you guys want it.
I will start by listing what I have accomplished so far:
- As described in previous posts - tree view & tree updates using the library thread which works in the background
- WordCompletion - attempts to complete a word under the cursor when hot key is pressed ( in the demo it is Ctrl+Space ), if single match is found, the word is inserted automatically no list box is poped, other wise, user selection box pops up (scintilla built in)
- CodeCompletion - typing an operator . or -> will attempt to parse the expression and to evaluate its return value, this is done with no limit of how complex the sentence is. for example: GetClassBox().GetBox().GetName(), a popup box will be shown for every operator (if a match will be found).
- Partial casting is supported (currently, only 'C' style casting is supported)
- All files were build and tested using g++ 3.4.5 MinGW, makefile is provided, you may need to alter it a bit, but the hard part of converting to code to compile under g++ is behind me (pheww, MSVC warning level 4 didnt do the job i got hundreds of errors when attempted to build with g++, especially with templates)
- Batch API was added to allow adding multiple files at a time to the database (in the demo you can select File->Add source file -> and select multiple files)
- Smart file parsing, if for example you have only the implementation of a function :
int Rectange::GetTopRight() {}
and the class Rectangle is declared in another file, which you did not add to the database, the library will automatically identifies that something is missing (in our case Rectange) and will 'fill' the space with 'dummy' entry to the tree view and the database. Once the real entry is added it will replace the dummy one.
Need to be added with minimum effort:
- Scope operator ( :: )
- this pointer & *this
- C++ casting (static_cast, dynamice, const_cast, reintepret_cast) style
- Identify whether an indentifier is a pointer or reference (or object), currently it responds for both regardless the type (e.g. Box *b; b. <-- will open a popup box)
I think that the code is well documented and can be easily read and followed.
The source files can be retrieved at:
http://www.eistware.com/wxes/codelite/CodeLite_sources.zip (http://www.eistware.com/wxes/codelite/CodeLite_sources.zip)
to build the demo, you will need the following:
wxscintilla, wxsqlite3 and wxcontrols (already provided, under sdk/gcc_lib)
Setup for the demo:
http://www.eistware.com/wxes/codelite/LiteEditor.exe (http://www.eistware.com/wxes/codelite/LiteEditor.exe)
Eran
can you post the cb project file please
Of course, will commit when I get the missing files.
Suggestion: can you remove the wxControls dependency? I know they're nice, but they're not necessary in this case (and the debug version weights 15mb). With wxScintilla and wxFlatNotebook is enough for demoing purposes.
Sure no problem, I forgot about their size ... (i uploaded the whole thing from work where I have high upload bandwidth)
Remember also that the wxFlatNotebook implementation is missing.
I didnt try to build it with UNICONDE, since I am not very familiar with it, if you can provide me with guidelies, I will be happy to do it
It's really easy.
For compiling the wxWidgets library you would normally issue the command mingw32-make -f makefile.gcc
For compiling the UNICODE version just add the parameter UNICODE=1
Example:
set path=C:\MinGW\bin;C:\mingw\mingw32\bin
cd C:\wxWidgets-2.6.3\build\msw
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1
For using it in the makefile, since I noticed you're using my tool, you'll only need to change to the resulting directory
as in WXCFG=gcc_dll\mswud.
For fixing the code reading this article might help: http://wiki.codeblocks.org/index.php?title=Unicode_Standards
I did prepared the infrastrcutre to support it (look at the database at the table strcuture, you will see there column for it already and it is populated where there is a match), anyway, should be easy to add (just run some more querys on the database)
And add a checkbox somewhere to toggle inherited members viewing off, since sometimes is useful to toggle it off.
As for the WordCompletion, it seems to work ok for the most cases Very Happy, but I get usually 0 matches with local scope variables.
Can you give me a sample source file where it does not work?, the local scope does not support (currently) function arguments
So that was, I was trying function arguments and they didn't worked. But I found other local scope variables that doesn't works.
I'll point later the failing cases (I'm testing it mainly with parsing the C::B SDK).
Adding combos above the tree view - is easy
Oh no, ignore the combos part, I was pointing the tooltips in the tree with comments/documentation being shown.
Parsing comments, well, I think there is a more useful feature before that,
Hehe, it's arguable the usefulness since with tooltips you don't even need to click and open the file (which might be even missing from disk but present in the DB?).
that you didnt mention:
symbol browsing from the editor, if you worked with vslick it is Ctrl+. or Ctrl+, in visual studio, right click->Go to definition
very useful feature, and very easy to implement it once you have SQL database of all tags.
It's really useful but I didn't asked, since I taked it for granted (as current C::B CodeCompletion haves the "Go to definition/declaration" feature). :P
I've sent you a mail with more info. :)
Even after this great work on the parser thingy, the following still confused it:
#if defined(NO_INITIAL_ALPHA_PFILEDIRS) || defined(WIN32)
if(file_exists(PLAYER_DIR "%s.plr", first_name)){
#else
if(file_exists(PLAYER_DIR "%c" DIR_SYM "%s.plr", first_name[0], first_name)){
#endif
After that bit, it won't parse any new functions, and keep thinking it's in the function it's in at that moment.
It'd be like, really cool if this somehow could be fixed, cos it misses out alot of symbols this way.
If you have any questions, or would like to see the whole file or sumthin, give a holla.
Great work Eranif
I compiled everything from the repository today (mingw).
I noticed something for local scope variables. Here is an example:
void f() {
int aa; // 1
#define BLAH // 2
int bb; // 3
}
Ctrl+space works fine with aa or bb.
Now remove line 1. There is no match for bb.
We have to remove the preprocessor keyword (line 2) if we want bb to be matched again.
It seems there is a little problem with preprocessor instructions.
Not sure if I can track the bug. I'll try to understand your codebase before.
Anyway, keep up the good work!
Well... I again tried to compile this "beast" ;-). Now that there are C::B project files in SVN (r59) I didn't have to adjust a lot (nice work!). Everything compiles nicely but in the end the linkage fails for a reason I don't understand. Here is the linker's output:
mingw32-g++.exe -LD:\Devel\wxWidgets\lib\gcc_dllUnicode -L..\CodeLite\lib -L..\sdk\wxscintilla\lib -L..\sdk\wxsqlite3\lib -L..\sdk\sqlite3\lib -LD:\Devel\GCC345\lib -o bin\LiteEditor.exe .obj\Release\cpp_symbol_tree.o .obj\Release\editor.o .obj\Release\editor_config.o .obj\Release\frame.o .obj\Release\resources.o .obj\Release\wxFlatNotebook.o .obj\Release\app.o .obj\Release\code_parser.res -s -Wl,--enable-auto-image-base -Wl,--export-all-symbols -Wl,--add-stdcall-alias -lcodelite_wxdll -lwxscintilla_wxdll -lwxsqlite3_wxdll -lsqlite3 -lwxmsw26u -mwindows
..\CodeLite\lib/libcodelite_wxdll.a(symbol_tree.o):symbol_tree.cpp:(.text+0x713d): undefined reference to `_imp__wxEVT_COMMAND_SYMBOL_TREE_ADD_ITEM'
..\CodeLite\lib/libcodelite_wxdll.a(symbol_tree.o):symbol_tree.cpp:(.text+0x7163): undefined reference to `_imp__wxEVT_COMMAND_SYMBOL_TREE_DELETE_ITEM'
..\CodeLite\lib/libcodelite_wxdll.a(symbol_tree.o):symbol_tree.cpp:(.text+0x718f): undefined reference to `_imp__wxEVT_COMMAND_SYMBOL_TREE_UPDATE_ITEM
'
collect2: ld returned 1 exit status
I realised that the missing export is actually declared in parse_thread.h... Any idea what I am missing here?!
With regards, Morten.
if you want to run it from the LiteEditor\bin directory, you have to copy the files
liteeditor.xml, sqlite3.dll and ctags.exe there too , it runs fine for me using wx263.dll
For the wx-config LiteEditor project I've set post-build steps:
cmd /c copy /y ..\sdk\sqlite3\lib\msw_gcc\sqlite3.dll bin\msw_gcc\
cmd /c copy /y ..\sdk\ctags\bin\msw_gcc\ctags.exe bin\msw_gcc\
cmd /c copy /y liteeditor.xml bin\msw_gcc\
i would be interested if it builds and runs fine for you too
Everything works fine now in all configurations in both projects. :)
ctags is obviously not good enough to parse wxwidgets
and gets confused with the heavy usage of macros
Yes I've noticed that about WXUNUSED.
Fortunately ctags haves a switch to specially handle identifiers like that.
See the -I identifier-list option in the manual: http://ctags.sourceforge.net/ctags.html
So we'll only need to have a user-configurable list of troublesome identifiers.
Ideal for libraries which haves heavy macro usage. Modern libraries with little-to-no-macro-usage will not need that.
Little example from the manual:
CLASS Example
{
// your content here
};
The example above uses "CLASS" as a preprocessor macro which expands to something different for each platform. For instance CLASS may be defined as "class __declspec(dllexport)" on Win32 platforms and simply "class" on UNIX. Normally, the absence of the C++ keyword "class" would cause the source file to be incorrectly parsed. Correct behavior can be restored by specifying -I CLASS=class.
I cannot compile "Debug wxdll unicode" project under XP CB SVN 3087.
Even though readtags.cpp and readtags.h are checked to be compiled under the ctags target, they are never loaded and compiled. Note that compilation jumps from read.c to rexx.c skipping readtags.cpp
-------------- Build: ctags in Debug wxdll unicode ---------------
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\args.c -o .objs\msw_wxdll_ud\sdk\ctags\args.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\asm.c -o .objs\msw_wxdll_ud\sdk\ctags\asm.o
...<snip>...
-IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\python.c -o .objs\msw_wxdll_ud\sdk\ctags\python.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\read.c -o .objs\msw_wxdll_ud\sdk\ctags\read.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\rexx.c -o .objs\msw_wxdll_ud\sdk\ctags\rexx.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\routines.c -o .objs\msw_wxdll_ud\sdk\ctags\routines.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\ruby.c -o .objs\msw_wxdll_ud\sdk\ctags\ruby.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\scheme.c -o .objs\msw_wxdll_ud\sdk\ctags\scheme.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\sh.c -o .objs\msw_wxdll_ud\sdk\ctags\sh.o
mingw32-gcc.exe -Wall -g -pipe -fmessage-length=0 -mthreads -Winvalid-pch -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -I.objs\msw_wxdll_ud\CodeLite -I- -I.objs\msw_wxdll_ud\CodeLite -I. -IC:\Usr\Proj\wxWidgets263\include -IC:\Usr\Proj\wxWidgets263\lib\gcc_dll\mswu -Isdk\ctags -IC:\MinGW\include -Isdk\ctags -IC:\Usr\Proj\cbCodeLite\ -c sdk\ctags\slang.c -o .objs\msw_wxdll_ud\sdk\ctags\slang.o
...<snip>...
.objs\msw_wxdll_ud\sdk\ctags\sql.o .objs\msw_wxdll_ud\sdk\ctags\strlist.o .objs\msw_wxdll_ud\sdk\ctags\tcl.o .objs\msw_wxdll_ud\sdk\ctags\verilog.o .objs\msw_wxdll_ud\sdk\ctags\vim.o .objs\msw_wxdll_ud\sdk\ctags\vstring.o .objs\msw_wxdll_ud\sdk\ctags\yacc.o -lwxmsw26u
mingw32-g++.exe: .objs\msw_wxdll_ud\sdk\ctags\readtags.o: No such file or directory
Process terminated with status 1 (0 minutes, 3 seconds)
0 errors, 0 warnings
(http://img236.imageshack.us/img236/7766/graphic1015200644809pmcu0.png)
this looks very nice.
in time it will be a very good code completion plugin..
as for the "heavy macros";
parse all macros to a database, then when parsing a line, "dereference" the macros till there are no macro references left.
for example.
1. //used in GCC i thought
2. #define DLL_EXPORT _attribute_((export))
3. #define CLASS class DLL_EXPORT
4. CLASS someclass
5. {
6. /* some stuff */
7. };
1. { we are parsing line 4 {
2. find CLASS in macro db
3. found CLASS, {replace
4. class is not a macro
5. found DLL_EXPORT, {replace
6. _attribute_ and export are not macros } }
7. someclass is not a macro }
8. start parsing definitions, declarations etc.
line that it is parsing is 'class _attribute_((export)) someclass'}
this could fix the "heavy macro" "bug"... just an idea :)
thought it has performance impact... but at least its correct
if you manage the database well, like ordering entries by name u can make a very fast algorithm to search for definitions and declarations.
and if u make it so it only parses on a new project and if u edit a line performance impact should not be noticable when programming (unlike intellisense, blegh)
@Eranif
In the buildinfo.txt for MSW there is an .cbp for sqlite3 and wxsqlite3.
The project for sqlite3 does not compile because there are no source files for it downloaded by SVN(url="http://svn.berlios.de/svnroot/repos/codelite/trunk")
What is the difference, and which project is correct?
Code::Blocks (CB) workspace and project files are supplied
! two build methods are supplied !
1. CodeLite.workspace
contains the CB-projects
* sdk\wxconfig\wx-config-win.cbp
* sdk\ctags\build\ctags.cbp
* sdk\sqlite3\build\sqlite3.cbp
* sdk\wxsqlite3\build\wxsqlite3_wxsqlite3.cbp
* CodeLite\CodeLite.cbp
* sdk\wxscintilla\build\wxscintilla.cbp
* LiteEditor\LiteEditor.cbp