From 23b3327b1daf6fa5260cf1184e5b8d90645323a3 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 2 Oct 2018 15:28:28 +0200 Subject: [PATCH] Fixed completions of global vars and tensorflow slowness, fixes #1228, #1116 --- jedi/api/__init__.py | 19 ++++++++++++------- test/completion/basic.py | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index c652b368e..9e568cf8f 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -178,17 +178,22 @@ def completions(self): ) completions = completion.completions() - import_completions_count = len([ - c for c in completions - if not c._name.tree_name - or c._name.tree_name.get_definition().type in ('import_name', 'import_from') - ]) - if import_completions_count > 10: + def iter_import_completions(): + for c in completions: + tree_name = c._name.tree_name + if tree_name is None: + continue + definition = tree_name.get_definition() + if definition is not None \ + and definition.type in ('import_name', 'import_from'): + yield c + + if len(list(iter_import_completions())) > 10: # For now disable completions if there's a lot of imports that # might potentially be resolved. This is the case for tensorflow # and has been fixed for it. This is obviously temporary until we # have a better solution. - self._evaluator.infer_enabled = True + self._evaluator.infer_enabled = False debug.speed('completions end') return completions diff --git a/test/completion/basic.py b/test/completion/basic.py index ae2e3128e..c51197e3f 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -154,6 +154,9 @@ def global_define(): #? int() global_var_in_func +#? ['global_var_in_func'] +global_var_in_f + def funct1(): # From issue #610 @@ -175,6 +178,7 @@ def init_global_var_predefined(): #? int() None global_var_predefined + # ----------------- # within docstrs # -----------------