Menu

#1319 code completion should add priority to current scope

open
nobody
None
5
2011-04-22
2011-04-22
YoHell
No

Ways to reproduce:
1. Create python module moo.py, as:
cow = 1
co
2. press Ctrl-Space to activate code completion for word co.
3. First suggestion is 'co' (dynamic import from traceback package), while the name cow (my local variable) is found farther down the list at 7th place.

What I expect to see:
Names in my current scope at the top of the list, possibly with priority to local variable names. (I realize you list exact matches (from anywhere) at the top, but that's just no good; see below.)

Why I expect it:
Most programmers use names that already exist in the current scope way more frequently than they import new names (duh!), and for optimal usability, the most frequently used options should be the most easily accessible ones, rather hidden among other, less frequently used options.

Why current behavior is bad:
My variable is harder to directly see in this place, and my spinal chord never gets completely convinced this is really "my" cow and not some dynamic import that will get added to the top of the file, and which I'll have to remember to check for, and also remember that I never actually intended to use and so possibly delete at some later point in time, so I often spend seconds looking at this list, making sure this choice will really do what I want and with no side effects, and losing my train of thought instead of writing code.
This right here is why I post this as a bug rather than a feature request. This is important enough that I find myself favoring the emacs-like Alt-/ raw text completion despite all the code completion sweetness built into pydev. Its a lot more (and more awkward) keypresses; multiple Shift-Alt-7 on my keyboard, but at least it always does what I expect it to do, quickly and consistently.

Additional guesswork:
Given that code tends to be organized in functional blocks even within scopes, a likely guess would be that the most recently used names are also the ones that are most likely to be used again, so perhaps it would be useful to rank matching names in the current scope by distance from the cursor (lines/chars some other metric?). Or maybe an alphabetized list is more efficient because of consistency, possibly with priority to local variables. Dunno. Guess that's something one would have to test.

Discussion