diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 46cf4247..4c408877 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -130,9 +130,24 @@ class Script(object): return ((k, bs) for k in keywords.keyword_names('import')) 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') path = self._user_context.get_path_until_cursor() - if re.search('^\.|\.\.$', path): + if not completion_possible(path): return [] path, dot, like = helpers.completion_parts(path) diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 44f94c7b..831b215f 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -50,3 +50,14 @@ def test_line_number_errors(): # ok api.Script(s, 1, 0) 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'