Author Topic: Include completion improved  (Read 17916 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Include completion improved
« on: June 01, 2009, 08:59:00 pm »
Hello,
Here is a patch for the codecompletion plugin,
that tries to improve the include file completion.

Improvements:
1. Parse correctly:
Code
#    include "ala-bala"
    #   include "ala-bala"

2. Use the project/active target include dirs to simplify the entries in the auto-complete list.
In my projects, I always put the source (*.h/*.cpp) files in subdirectory "src" and add it as an include path to the projects.
This let me use the headers without the "src/" prefix.
In the patch, the file path is modified, so it doesn't start with the include dir (the dir is stripped from the path).
So I can type the file path relative to the src directory and the completion list has the correct entries.
I've tested it only on linux and I need some help to handle paths in platform independent way (handle paths with \ instead of /)
Also I'm not sure how to handle ./ or ../ added to include dir. Any help here will be appreciated
Code
#include "file1.h"
#include "dir1/file2.h"

3. Fixed a bug in the usage of the "caseSens" option
Code
-        ed->GetControl()->AutoCompSetIgnoreCase(caseSens);
+        ed->GetControl()->AutoCompSetIgnoreCase(!caseSens);

KNOWN PROBLEM:
The closing '"' or '>' is not added automatically and I couldn't find a way to implement it.
If anyone knows (and shares this info) if there is a message, that I can handle to add the one of the two characters, I'll be very thankful.

Best regards

p.s. the patch is attached
p.s.s. the patch is made against the 5617 wxaui branch


[attachment deleted by admin]
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Include completion improved
« Reply #1 on: June 03, 2009, 04:38:58 am »
Your message has much information, so, it will take me a lot of time to absorb. :D

Lets take the path related aspect, I found it was there: In Globals.cpp

Code
bool NormalizePath(wxFileName& f,const wxString& base)
{
    bool result = true;
//    if(!f.IsAbsolute())
    {
        f.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, base);
        result = f.IsOk();
    }
    return result;
}


In Parser.cpp

Quote
wxArrayString Parser::FindFileInIncludeDirs(const wxString& file,bool firstonly)
{
    wxArrayString FoundSet;
    for(size_t idxSearch = 0; idxSearch < m_IncludeDirs.GetCount(); ++idxSearch)
    {
        wxString base = m_IncludeDirs[idxSearch];
        wxFileName tmp = file;
        NormalizePath(tmp,base);
        wxString fullname = tmp.GetFullPath();
        if(wxFileExists(fullname))
        {
            FoundSet.Add(fullname);
            if(firstonly)
                break;
        }
    } // end for : idx : idxSearch
//    Manager::Get()->GetLogManager()->DebugLog(_T("Searching %s"), file.c_str());
//    Manager::Get()->GetLogManager()->DebugLog(_T("Found %d"), FoundSet.GetCount());
    return FoundSet;
} // end of FindFileInIncludeDirs


Also, I searched on Google, and this page will give a more details:

http://lists.wxwidgets.org/pipermail/wx-users/2007-January/096389.html

Quote
> *bool* *Normalize*(*int */flags = wxPATH_NORM_ALL/, *const wxString&
> */cwd = wxEmptyString/, *wxPathFormat */format = wxPATH_NATIVE/)
>
> Normalize the path: with the default flags value, the path will be made
> absolute, without any ".." and "." and all environment variables will be
> expanded in it this may be done using another (than current) value of cwd


Maybe, it's helpful or not, I'm not sure. :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #2 on: June 03, 2009, 07:36:12 am »
Quote
In my projects, I always put the source (*.h/*.cpp) files in subdirectory "src" and add it as an include path to the projects.
This let me use the headers without the "src/" prefix.
In the patch, the file path is modified, so it doesn't start with the include dir (the dir is stripped from the path).
So I can type the file path relative to the src directory and the completion list has the correct entries.

Is not already the case that CB offers both, like :
 "./src/MyHeader.h
 "MyHeader.h"  ??

Should recheck.

While you are at it, could you look at the following issue : I am trying out another patch that tries to put closing quotes/double quotes/braces/brackets/... when you type the opening one.
This has however a negative effect on the include completion since what happens is :

I type :
Code
#include "

and I get :
Code
#include ""
with the cursor between the 2 ". But that has killed the include completion.


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Include completion improved
« Reply #3 on: June 03, 2009, 12:51:22 pm »
ollydbg, thanks I'll take a look at it tonight.

Is not already the case that CB offers both, like :
 "./src/MyHeader.h
 "MyHeader.h"  ??

Should recheck.
You talk about the case when you have both files, and the ./src is added to the include paths?

While you are at it, could you look at the following issue : I am trying out another patch that tries to put closing quotes/double quotes/braces/brackets/... when you type the opening one.
This has however a negative effect on the include completion since what happens is :

I type :
Code
#include "

and I get :
Code
#include ""
with the cursor between the 2 ". But that has killed the include completion.

I suppose you talk about: http://forums.codeblocks.org/index.php/topic,10361.0.html
I've not tested it, because I don't like the feature. I'll give it a try.
I suppose the problem is something like that:
1. The user types a " or <
2. The list opens
3. The brace completion kicks in and places a character
4. The list closes because of the placed character
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #4 on: June 03, 2009, 02:35:10 pm »
I guess something like that, or the character inserted event is no longer past on .. to investigate ;-)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Include completion improved
« Reply #5 on: June 03, 2009, 10:38:56 pm »
Here is a little update:

1. Used NormalizePath when obtaining the include dirs
2. Replace '\' with '/' everywhere, because I'm not sure what character is used on windows for the paths and also that is the standard (portable) way to write include paths.

[attachment deleted by admin]
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #6 on: June 04, 2009, 03:11:54 pm »
ok, I have done a very quick look at the (original/official) code. And there are a few things that could be improved.

Step 1 : get rid of unused stuff :
Code
    // find opening quote (" or <)
    int idx = pos - lineStartPos;
    int found = -1;
    wxString filename;
    while (idx > 0)
    {
        wxChar c = line.GetChar(idx);
        if (c == _T('>'))
            return; // the quote is closed already...
        else if (c == _T('"') || c == _T('<'))
        {
            if (found != -1)
                return; // the already found quote was the closing one...
            found = idx + 1;
        }
        else if (c != _T(' ') && c != _T('\t') && !found)
            filename << c;
        --idx;
    }
The filename is NOT used, so in my private copy I will first make things simpler, and remove it.


Secondly :
Code
    // fill a list of matching project files
    wxArrayString files;
    for (int i = 0; i < pPrj->GetFilesCount(); ++i)
So only file of the current project seems to be added. So no files in that nice include directory that I added to my project ;-)

And then we see :
Code
            wxFileName fname(pf->relativeFilename);
            if (files.Index(pf->relativeFilename) == wxNOT_FOUND)
                files.Add(pf->relativeFilename);
            if (files.Index(fname.GetFullName()) == wxNOT_FOUND)
                files.Add(fname.GetFullName());
So that means it should be twice in the list : full path and relative.
EDIT : well actually something like this; Say I have a header in my project whose relative path to the cbp file is ../../inc/MyHeader.h, then there will be 2 entries in the list :
1)../../inc/MyHeader.h
2)MyHeader.h

Note : this is from looking at the code, not from testing.


Ideas :
* Also add all headers that can be found in the include dirs.
* add all headers of all projects in the workspace
* ...

off course the more files being added the slower things will get.

But as it is now, I agree, most of the time the completion for include files just fails.
« Last Edit: June 04, 2009, 05:11:32 pm by killerbot »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #7 on: June 04, 2009, 03:52:16 pm »
I can confirm :

Code
        ed->GetControl()->AutoCompSetIgnoreCase(caseSens);
should be
Code
        ed->GetControl()->AutoCompSetIgnoreCase(!caseSens);

Will already fix this in svn.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Include completion improved
« Reply #8 on: June 04, 2009, 06:18:03 pm »
Hi, great review for the official code, can you do the same with my patch?  8)

My patch is concerned with making the completion usable and adding files outside of the project is out of its scope.  :lol:

But you are right, it would be nice to have the compiler includes completed, also on linux /usr/include/ is a good candidate.
But this requires some kind of caching, there is no need to traverse the filesystem every time the user wants to complete an include!

There should be some discussion and if there is an agreement how the thing should be implemented I can do it  :lol:
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: Include completion improved
« Reply #9 on: June 04, 2009, 11:27:00 pm »
Hi

Are you sure you tested the last patch from http://developer.berlios.de/patch/?func=detailpatch&patch_id=2746&group_id=5358?

Because one of the first tests in BraceCompletion patch is
Code
 if ( IsComment(style) || IsPreprocessor(style) ) return; 

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #10 on: June 05, 2009, 12:17:57 am »
I updated the application of the patch, I was using an older version.  :?

Seems to work better, and at first sight seems to work better on other issues too ....
« Last Edit: June 05, 2009, 12:28:22 am by killerbot »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Include completion improved
« Reply #11 on: June 05, 2009, 06:34:15 am »
I updated the application of the patch, I was using an older version.  :?
Just for the record: Please be careful with CC patches. Remember we are testing a massively enhanced version. I'll try to keep everything in sync but probably it's better to inform (me) before adding to trunk. Otherwise it's getting more and more hard for me... :roll:
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #12 on: June 05, 2009, 09:10:34 am »
that patch kicks in on the cbeditor, not the CC.

I am currently only looking at CC for the : "CodeCompleteIncludes()"

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Include completion improved
« Reply #13 on: July 14, 2009, 11:24:36 am »
Is my patch being applied? Because it seems so...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Include completion improved
« Reply #14 on: July 14, 2009, 12:59:19 pm »
I think I did, can you double check the source code ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Include completion improved
« Reply #15 on: July 14, 2009, 01:07:55 pm »
I've checked and it seems that it is fully applied. I'm looking at the CC branch.

Thanks
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]