-
-
Notifications
You must be signed in to change notification settings - Fork 246
Show single underscore attributes before double underscore ones #528 #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
599c8b3
18442e3
d1b9c2b
f9c273c
e9f1796
dd0f284
333527f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…score ones"
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,6 +256,7 @@ def matches(self, cursor_offset, line, **kwargs): | |
if not r.word.split('.')[-1].startswith('_'): | ||
matches = set(match for match in matches | ||
if not match.split('.')[-1].startswith('_')) | ||
# MAYBE HERE 2 ?? | ||
return matches | ||
|
||
def locate(self, current_offset, line): | ||
|
@@ -311,6 +312,8 @@ def attr_lookup(self, obj, expr, attr): | |
for word in words: | ||
if self.method_match(word, n, attr) and word != "__builtins__": | ||
matches.append("%s.%s" % (expr, word)) | ||
# print 'matches', matches | ||
# ORGANIZE THE THINGS HERE MAYBE 1?? | ||
return matches | ||
|
||
if py3: | ||
|
@@ -543,13 +546,31 @@ def get_completer(completers, cursor_offset, line, **kwargs): | |
complete_magic_methods is a bool of whether we ought to complete | ||
double underscore methods like __len__ in method signatures | ||
""" | ||
|
||
for completer in completers: | ||
matches = completer.matches(cursor_offset, line, **kwargs) | ||
if matches is not None: | ||
return sorted(matches), (completer if matches else None) | ||
if len(matches) > 0: | ||
matches = sort_by_underscore(matches) | ||
return matches, (completer if matches else None) | ||
return [], None | ||
|
||
def sort_by_underscore(matches): | ||
"""Sort single underscore attributes before double underscore ones. | ||
""" | ||
matches = sorted(matches) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't really matter, but I'd prefer |
||
if len(matches) == 0 or len(matches) == 1: | ||
return matches | ||
one_underscore = None | ||
for i in xrange(1, len(matches)+1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I bet we could do this with a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The list of matches starts with the name of the variable, etc. before the attribute (eg. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I'm sorting in the wrong place, which is totally plausible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm I didn't actually test these so they might not be right, but there just might be some nice way similar to one of these. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, Yeah, the way I did this is a bit hacky... I'll see if there's somewhere else where I can make this solution nicer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok so these won't actually work, but if there is some nice way to do On Thu, Sep 10, 2015 at 12:20 PM, Wes E. Vial notifications@github.com
|
||
i = -i | ||
dot_i = matches[i].rfind('.') + 1 | ||
if matches[i][dot_i] == '_' and matches[i][dot_i+1] != '_': | ||
one_underscore = i | ||
else: | ||
break | ||
if one_underscore_i != None: | ||
return matches[one_underscore:] + matches[:one_underscore] | ||
return matches | ||
|
||
def get_default_completer(mode=SIMPLE): | ||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a few comments made it in by accident