1
0
forked from VimPlug/jedi

Finally fix all tests.

This commit is contained in:
Dave Halter
2016-07-25 00:14:42 +02:00
parent ebbaaf7ad2
commit aeb734564c
3 changed files with 6 additions and 14 deletions

View File

@@ -80,7 +80,7 @@ class Completion:
self._code_lines = code_lines self._code_lines = code_lines
# The first step of completions is to get the name # The first step of completions is to get the name
self._like_name = helpers.get_on_completion_name(module, position) self._like_name = helpers.get_on_completion_name(module, code_lines, position)
# The actual cursor position is not what we need to calculate # The actual cursor position is not what we need to calculate
# everything. We want the start of the name we're on. # everything. We want the start of the name we're on.
self._position = position[0], position[1] - len(self._like_name) self._position = position[0], position[1] - len(self._like_name)

View File

@@ -20,23 +20,16 @@ def sorted_definitions(defs):
return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0)) return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0))
def get_on_completion_name(module, position): def get_on_completion_name(module, lines, position):
leaf = module.get_leaf_for_position(position) leaf = module.get_leaf_for_position(position)
if leaf is None: if leaf is None:
return '' return ''
elif leaf.type == 'string': elif leaf.type in ('string', 'error_leaf'):
# Completions inside strings are a bit special, we need to parse the # Completions inside strings are a bit special, we need to parse the
# string. # string.
lines = leaf.value.splitlines() line = lines[position[0] - 1]
start_pos = leaf.start_pos
difference = position[0] - start_pos[0]
if difference == 0:
indent = start_pos[1]
else:
indent = 0
line = lines[difference][:position[1] - indent]
# The first step of completions is to get the name # The first step of completions is to get the name
return re.search(r'(?!\d)\w+$|$', line).group(0) return re.search(r'(?!\d)\w+$|$', line[:position[1]]).group(0)
elif leaf.type not in ('name', 'keyword'): elif leaf.type not in ('name', 'keyword'):
return '' return ''
@@ -129,7 +122,6 @@ def get_stack_at_position(grammar, code_lines, module, pos):
safeword = 'XXX_USER_WANTS_TO_COMPLETE_HERE_WITH_JEDI' safeword = 'XXX_USER_WANTS_TO_COMPLETE_HERE_WITH_JEDI'
# Remove as many indents from **all** code lines as possible. # Remove as many indents from **all** code lines as possible.
code = dedent(code + safeword) code = dedent(code + safeword)
print(repr(code))
p = parser.Parser(grammar, code, start_parsing=False) p = parser.Parser(grammar, code, start_parsing=False)
try: try:

View File

@@ -74,7 +74,7 @@ def setup_readline(namespace_module=__main__):
lines = common.splitlines(text) lines = common.splitlines(text)
position = (len(lines), len(lines[-1])) position = (len(lines), len(lines[-1]))
name = get_on_completion_name(interpreter._get_module(), position) name = get_on_completion_name(interpreter._get_module(), lines, position)
before = text[:len(text) - len(name)] before = text[:len(text) - len(name)]
completions = interpreter.completions() completions = interpreter.completions()
finally: finally: