diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index afceea84..c652b368 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -177,6 +177,19 @@ class Script(object): self._pos, self.call_signatures ) 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: + # 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 + debug.speed('completions end') return completions diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index d316785f..48339439 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -105,6 +105,9 @@ class Evaluator(object): self.is_analysis = False self.project = project self.access_cache = {} + # This setting is only temporary to limit the work we have to do with + # tensorflow and others. + self.infer_enabled = True self.reset_recursion_limitations() self.allow_different_encoding = True @@ -123,6 +126,9 @@ class Evaluator(object): return self.project._get_sys_path(self, environment=self.environment) def eval_element(self, context, element): + if not self.infer_enabled: + return NO_CONTEXTS + if isinstance(context, CompForContext): return eval_node(context, element) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 357d26cc..757aec52 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -32,8 +32,12 @@ def get_string_context_set(evaluator): return builtin_from_name(evaluator, u'str').execute_evaluated() -def load_module(evaluator, **kwargs): - access_path = evaluator.compiled_subprocess.load_module(**kwargs) +def load_module(evaluator, dotted_name, **kwargs): + # Temporary, some tensorflow builtins cannot be loaded, so it's tried again + # and again and it's really slow. + if dotted_name.startswith('tensorflow.'): + return None + access_path = evaluator.compiled_subprocess.load_module(dotted_name=dotted_name, **kwargs) if access_path is None: return None return create_from_access_path(evaluator, access_path) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 99791dc9..3b1df31a 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -21,7 +21,6 @@ from jedi._compatibility import (FileNotFoundError, ImplicitNSInfo, force_unicode, unicode) from jedi import debug from jedi import settings -from jedi.common.utils import traverse_parents from jedi.parser_utils import get_cached_code_lines from jedi.evaluate import sys_path from jedi.evaluate import helpers @@ -279,7 +278,7 @@ class Importer(object): return sys_path_mod def follow(self): - if not self.import_path: + if not self.import_path or not self._evaluator.infer_enabled: return NO_CONTEXTS return self._do_import(self.import_path, self.sys_path_with_modifications())