Code::Blocks
September 23, 2014, 06:22:04 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: The new Release 13.12 is out! You can download binaries for windows, mac and many major linux distros from  http://www.codeblocks.org/downloads/26 .
 
   Home   Help Search Login Register  :: WebsiteWiki  
Pages: [1] 2  All   Go Down
  Send this topic  |  Print  
Author Topic: Can code completion be made contextual?  (Read 4294 times)
carra
Advanced newcomer
*
Offline Offline

Posts: 108


« on: July 06, 2012, 09:57:37 am »

Code completion in C::B is really useful, but it seems to behave worse when there are big lists of candidates. This happens whenever you include big headers (such as <windows.h>), because the only critera for suggesting candidates seems to alphabetic sorting. Think, for instance, a Windows program where I have the following:

Code:
    UniString U( const string& Text )
    {
        UniString Result = U( Text.c_str() );
        Result += '\0';
       
        return Re  <-- HERE
    }

For anyone seeing this code, it would be very obvious that I want to write "Result", however due to windows definitions Code Completion suggests the following:

Code:
ReadClassStg
ReadClassStm
ReadConsole
ReadConsoleA
... (VERY long list)

All these Windows definitions have nothing to do with what I am writing. But the problem  is that, being THAT many, in many simple cases you end up having to write almost the whole word yourself to get the right suggestion. This is a clear indication that, when including big headers, a simple alphabetic sort is not the most useful criteria.

So my question here is if it would be feasible to change priorities in the suggestion list, so that local definitions are suggested first. In my experience I have found this would get the first suggestion right in a high percentage of cases, and would therefore save lots of times when programming.

What do you think about this?
Logged
ollydbg
Developer
Lives here!
*****
Offline Offline

Posts: 4081


Interests on OpenCV and Robotics


WWW
« Reply #1 on: July 07, 2012, 01:28:56 am »

I just review the code, and see that:
Code:
int CodeCompletion::CodeComplete()
adding all the tokens to show, and sort the show items.

If a Token is a local variable(automatic variable), it will have Token->m_IsTemp==true.
So, maybe, we can firstly scan those tokens, and put them in the beginning of the codecompletion list.

I'm currently working on other part of CC, so it is great if you can help us. Smiley

Add to:
005252
Logged

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.
oBFusCATed
Developer
Lives here!
*****
Offline Offline

Posts: 7606


« Reply #2 on: July 07, 2012, 02:11:33 pm »

Code:
if (result.size() <= m_CCMaxMatches)

Is this line correct?
I think this is a massive bug, because if there are more matches than the limit the list with matches won't be shown at all.
Am I correct?
Logged

<debugger plugin maintainer>
(most of the time I ignore long posts)
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8642



« Reply #3 on: July 07, 2012, 02:31:26 pm »

Code:
if (result.size() <= m_CCMaxMatches)
Is this line correct?
Yes - look below, the else tree will show a warning asking the user to increase the number of results. So not "nothing" is shown, but a warning.

Besides: The default number of results is really big - if this number is exceeded, it is more likely that something is seriously screwed.
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
oBFusCATed
Developer
Lives here!
*****
Offline Offline

Posts: 7606


« Reply #4 on: July 07, 2012, 02:45:09 pm »

I've set it to 200 in the UI, but this value is ignored, as "/max/matches" is only read, never set.
The config value set in the UI is "/max_matches" as far as I can see.

But again in my opinion this is broken, because the max_matches config variable should limit only the results shown in the listctrl, not the searching phaze.
Logged

<debugger plugin maintainer>
(most of the time I ignore long posts)
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8642



« Reply #5 on: July 07, 2012, 03:30:33 pm »

I've set it to 200 in the UI, but this value is ignored, as "/max/matches" is only read, never set.
The config value set in the UI is "/max_matches" as far as I can see.
If that is true, then this is really a bug. Tongue

But again in my opinion this is broken, because the max_matches config variable should limit only the results shown in the listctrl, not the searching phaze.
Well the point here is: How do you limit? The first, the last...?! Without an information provided to the user we will get a lot forum noise like "my function is not displayed" just because we silently strip the results. Here, instead, we show a warning so the user knows "There were many results, but we didn't know what to show.". I personally like this more... and that's why it is that way.

Of course if you prove me wrong or find a more clever solution - I am open for it.
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
oBFusCATed
Developer
Lives here!
*****
Offline Offline

Posts: 7606


« Reply #6 on: July 07, 2012, 03:55:20 pm »

Of course if you prove me wrong or find a more clever solution - I am open for it.
We can always add an item at the end - "number of matches reached the limit, please increase it to see all matches" or something like this.
Logged

<debugger plugin maintainer>
(most of the time I ignore long posts)
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8642



« Reply #7 on: July 07, 2012, 04:52:39 pm »

Of course if you prove me wrong or find a more clever solution - I am open for it.
We can always add an item at the end - "number of matches reached the limit, please increase it to see all matches" or something like this.
You mean "at the end of 16000 items"? Roll Eyes Then you can also print it to the hidden debug log or the NullLogger... Grin
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
oBFusCATed
Developer
Lives here!
*****
Offline Offline

Posts: 7606


« Reply #8 on: July 07, 2012, 05:05:31 pm »

No, at the 201-st item...
Logged

<debugger plugin maintainer>
(most of the time I ignore long posts)
carra
Advanced newcomer
*
Offline Offline

Posts: 108


« Reply #9 on: July 07, 2012, 07:53:25 pm »

I just review the code, and see that:
Code:
int CodeCompletion::CodeComplete()
adding all the tokens to show, and sort the show items.

If a Token is a local variable(automatic variable), it will have Token->m_IsTemp==true.
So, maybe, we can firstly scan those tokens, and put them in the beginning of the codecompletion list.

I'm currently working on other part of CC, so it is great if you can help us. Smiley

Add to:
005252
I've read that request description and the approach of presenting the last definitions first could also work. If I am thinking it correctly, the current function's variables are always going to be taken as the last in that context. And it would also be a pretty simple way of making big libraries (such as Windows, OpenGL, etc...) have low priority because they are commonly taken as a base to build custom code over them (and therefore are included BEFORE user definitions).

EDIT: Another possible approach could be to place first definitions parsed the active editor's file. This alternative could possibly be easier to implement (though, not as good).
« Last Edit: July 07, 2012, 09:37:40 pm by carra » Logged
Alpha
Developer
Lives here!
*****
Offline Offline

Posts: 1346



« Reply #10 on: March 08, 2013, 11:22:59 pm »

If a Token is a local variable(automatic variable), it will have Token->m_IsTemp==true.
So, maybe, we can firstly scan those tokens, and put them in the beginning of the codecompletion list.
This is possible, but requires modification to Scintilla (pending).

(I got distracted from my other work so...) Attached patch implements this.
Logged
p2rkw
Almost regular
**
Offline Offline

Posts: 141


« Reply #11 on: March 09, 2013, 12:56:00 am »

I implemented such feature: http://forums.codeblocks.org/index.php/topic,17146.msg119037.html#msg119037
but oBFusCATed told me that should be in separated patch so I removed this functionality.

My main goal was to sort list by item token's type, and place items with same type as expected type at top of the list.
But I didn't know how to detect expected type, so I only add criteria that was easier to implement.
« Last Edit: March 09, 2013, 12:58:13 am by p2rkw » Logged
Alpha
Developer
Lives here!
*****
Offline Offline

Posts: 1346



« Reply #12 on: March 09, 2013, 10:02:59 pm »

Interesting; I must have missed that when it was last discussed.  When you tried sorting, did you also have to modify Scintilla to allow non-alphabetical ordering?

One potential issue with priority sorting, is that if there are too many categories, the user will not see the names of alphabetically similar items close to each other, and may assume they do not exist.

By the way, I have tried CC with your patch (in rev. 8901), and if you type
Code:
wxString::app
you get 16 suggestions for append() (and Append()), one for each function overload.  Is this intended behaviour?
Logged
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8642



« Reply #13 on: March 10, 2013, 12:52:25 pm »

Attached patch implements this.
I'm afraid the last CC commit broke this. :-(
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
Alpha
Developer
Lives here!
*****
Offline Offline

Posts: 1346



« Reply #14 on: March 10, 2013, 06:18:17 pm »

I'm afraid the last CC commit broke this. :-(
Updated.

By the way, I have tried CC with your patch (in rev. 8901), and if you type
Code:
wxString::app
you get 16 suggestions for append() (and Append()), one for each function overload.  Is this intended behaviour?
src/plugins/codecompletion/codecompletion.cpp line 1012:
Code:
                static const bool ignoreOverloads = false;
                if (ignoreOverloads)
                {
                    // check hashmap for unique_strings
                    if (unique_strings.find(tmp) != unique_strings.end())
                        continue;
                }
Was this supposed to be user configurable?
Logged
Pages: [1] 2  All   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!