Skip to content

Commit

Permalink
Fixed completions of global vars and tensorflow slowness, fixes #1228,
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Oct 2, 2018
1 parent 075577d commit 23b3327
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions jedi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/completion/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -175,6 +178,7 @@ def init_global_var_predefined():
#? int() None
global_var_predefined


# -----------------
# within docstrs
# -----------------
Expand Down

0 comments on commit 23b3327

Please sign in to comment.