From 51d309b0a87969890d2b4e4591622ab63a952777 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 8 Dec 2014 15:52:05 +0100 Subject: [PATCH] Moved keyword completion around to get it working in all cases. --- jedi/api/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index d2aa7dda..4ec0ca88 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -131,6 +131,8 @@ class Script(object): :rtype: list of :class:`classes.Completion` """ def get_completions(user_stmt, bs): + # TODO this closure is ugly. it also doesn't work with + # simple_complete (used for Interpreter), somehow redo. module = self._parser.module() names, level, only_modules = helpers.check_error_statements(module, self._pos) completions = [] @@ -154,10 +156,14 @@ class Script(object): imp = imports.ImportWrapper(self._evaluator, name) completions += [(n, module) for n in imp.completion_names()] - if names or isinstance(user_stmt, pr.Import): - return completions - return self._simple_complete(path, dot, like) - + if not names and not isinstance(user_stmt, pr.Import): + if not path and not dot: + # add keywords + completions += ((k, b) for k in keywords.keyword_names(all=True)) + # TODO delete? We should search for valid parser + # transformations. + completions += self._simple_complete(path, dot, like) + return completions debug.speed('completions start') path = self._user_context.get_path_until_cursor() @@ -186,12 +192,6 @@ class Script(object): if p._definition.stars == 0: # no *args/**kwargs completions.append((p._name, p._name)) - if not path and not isinstance(user_stmt, pr.Import): - # add keywords - completions += ((k, b) for k in keywords.keyword_names(all=True)) - # TODO delete? We should search for valid parser - # transformations. - needs_dot = not dot and path comps = []