Author Topic: Can code completion be made contextual?  (Read 11289 times)

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Can code completion be made contextual?
« Reply #15 on: March 10, 2013, 10:29:49 pm »
Quote
When you tried sorting, did you also have to modify Scintilla to allow non-alphabetical ordering?
No, I didn't.
Take a look at CodeCompletion::CodeComplete: tokens' indices generated by m_NativeParser.MarkItemsByAI() are stored in separate list called m_AutocompNameIdx. In my implementation this list wasn't sorted only by tokens name but also by other token properties.

Quote
you get 16 suggestions for append() (and Append()), one for each function overload.  Is this intended behaviour?
Yes, it is. Overloaded functions can have different arguments, return value and documentation, so in my opinion they should be displayed as separated items.
But as you can see you can easily change this behaviour.

Wait a sec, I'll generate patch, so you will be able to test it.

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Can code completion be made contextual?
« Reply #16 on: March 10, 2013, 10:59:31 pm »
Attached patch is bit dirty because you can change sort criteria only in code, but you can see the idea.
I tell you more: you can even use different criteria in different cases, for example you can detect is autocomplete was opened in global scope and apply different criteria.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Can code completion be made contextual?
« Reply #17 on: March 13, 2013, 03:46:15 pm »
Overloaded functions can have different arguments, return value and documentation, so in my opinion they should be displayed as separated items.
Maybe a more optimal way would be to only show overloads as separate items if you are in global scope and function argument completion is enabled.
The documentation window could have a link to each of the overloads, and by default, show the overload with the most documentation first.

Quote
When you tried sorting, did you also have to modify Scintilla to allow non-alphabetical ordering?
No, I didn't.
I see.  The autocomp list jumps the selection as you type by searching the list for the given context with a binary search.  If the list is not alphabetized, the popup will often auto-cancel itself because it cannot find an entry (even though the entry exists).  (I had just been curious to see if you had come up with a cleaner solution than mine.)

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Can code completion be made contextual?
« Reply #18 on: March 14, 2013, 01:59:12 am »
I'm afraid the last CC commit broke this. :-(
Updated.
Just thought I should mention, if you value a non-crashing Code::Blocks, do not apply this patch...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5234
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Can code completion be made contextual?
« Reply #19 on: March 14, 2013, 02:19:49 am »
Quote
if you value a non-crashing Code::Blocks, do not apply this patch
Which do you think cause the crash issue? The concurrently access to the tokentree?
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 Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Can code completion be made contextual?
« Reply #20 on: March 14, 2013, 02:29:08 am »
I tried to do some magic with dual purposing the same std::vector sorting it in a partitioned manor so the temp variables would end up first.  Unfortunately, std::sort() somehow (in a pattern I cannot predict) sends invalid wxStrings to static int SortCCList(const wxString& first, const wxString& second) when I do this.