Skip to content

Commit 0db42ff

Browse files
document get_completer autocompletion helper
1 parent 6966e2e commit 0db42ff

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

bpython/autocomplete.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,26 @@
6060
def after_last_dot(name):
6161
return name.rstrip('.').rsplit('.')[-1]
6262

63-
def get_completer(cursor_offset, current_line, locals_, argspec, full_code, mode, complete_magic_methods):
63+
def get_completer(cursor_offset, current_line, locals_, argspec, current_block,
64+
mode, complete_magic_methods):
6465
"""Returns a list of matches and a class for what kind of completion is happening
6566
6667
If no completion type is relevant, returns None, None
6768
68-
argspec is an output of inspect.getargspec
69+
Params:
70+
cursor_offset is the current cursor column
71+
current_line is a string of the current line
72+
locals_ is a dictionary of the environment
73+
argspec is an inspect.ArgSpec instance for the current function where
74+
the cursor is
75+
current_block is the possibly multiline not-yet-evaluated block of
76+
code which the current line is part of
77+
mode is one of SIMPLE, SUBSTRING or FUZZY - ways to find matches
78+
complete_magic_methods is a bool of whether we ought to complete
79+
double underscore methods like __len__ in method signatures
6980
"""
7081

71-
kwargs = {'locals_':locals_, 'argspec':argspec, 'full_code':full_code,
82+
kwargs = {'locals_':locals_, 'argspec':argspec, 'current_block':current_block,
7283
'mode':mode, 'complete_magic_methods':complete_magic_methods}
7384

7485
# mutually exclusive if matches: If one of these returns [], try the next one
@@ -220,11 +231,11 @@ def format(cls, match):
220231
class MagicMethodCompletion(BaseCompletionType):
221232
locate = staticmethod(lineparts.current_method_definition_name)
222233
@classmethod
223-
def matches(cls, cursor_offset, line, full_code, **kwargs):
234+
def matches(cls, cursor_offset, line, current_block, **kwargs):
224235
r = cls.locate(cursor_offset, line)
225236
if r is None:
226237
return None
227-
if 'class' not in full_code:
238+
if 'class' not in current_block:
228239
return None
229240
start, end, word = r
230241
return [name for name in MAGIC_METHODS if name.startswith(word)]

0 commit comments

Comments
 (0)