1
0
forked from VimPlug/jedi

fix completion on int literals, fixes #327

This commit is contained in:
Dave Halter
2014-04-07 13:04:45 +02:00
parent 6ebc40792a
commit 99beac1c2b
2 changed files with 27 additions and 1 deletions

View File

@@ -130,9 +130,24 @@ class Script(object):
return ((k, bs) for k in keywords.keyword_names('import')) return ((k, bs) for k in keywords.keyword_names('import'))
return self._simple_complete(path, like) return self._simple_complete(path, like)
def completion_possible(path):
"""
The completion logic is kind of complicated, because we strip the
last word part. To ignore certain strange patterns with dots, just
use regex.
"""
dots = re.search('^\.|([\d.]+)\.$', path)
if dots:
literal = dots.group(1)
print(literal)
if re.search('\d\.|\.{3}', literal or ''):
return True
return False
return True
debug.speed('completions start') debug.speed('completions start')
path = self._user_context.get_path_until_cursor() path = self._user_context.get_path_until_cursor()
if re.search('^\.|\.\.$', path): if not completion_possible(path):
return [] return []
path, dot, like = helpers.completion_parts(path) path, dot, like = helpers.completion_parts(path)

View File

@@ -50,3 +50,14 @@ def test_line_number_errors():
# ok # ok
api.Script(s, 1, 0) api.Script(s, 1, 0)
api.Script(s, 1, len(s)) api.Script(s, 1, len(s))
def test_completion_on_int_literals():
# No completions on an int literal (is a float).
assert api.Script('1.').completions() == []
# Multiple points after an int literal basically mean that there's a float
# and a call after that.
#assert api.Script('1..').completions()[0].parent().name == 'float'
assert api.Script('1..').completions()[0]._definition.parent.name == 'float'
assert api.Script('1.0.').completions()[0]._definition.parent.name == 'float'