From e70c49fea2aa5ed8bce624e81540ef3e7c958182 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 17 May 2019 16:04:16 +0200 Subject: [PATCH] Use completions from both stubs and actual modules --- jedi/api/completion.py | 8 ++++++++ test/completion/stubs.py | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/jedi/api/completion.py b/jedi/api/completion.py index a156000f..d13cbbd3 100644 --- a/jedi/api/completion.py +++ b/jedi/api/completion.py @@ -11,6 +11,7 @@ from jedi.evaluate import imports from jedi.api import keywords from jedi.evaluate.helpers import evaluate_call_of_leaf, parse_dotted_names from jedi.evaluate.filters import get_global_filters +from jedi.evaluate.gradual.conversion import stub_to_actual_context_set from jedi.parser_utils import get_statement_of_position @@ -238,6 +239,13 @@ class Completion: for filter in context.get_filters( search_global=False, origin_scope=user_context.tree_node): completion_names += filter.values() + + for context in contexts: + stub_contexts = stub_to_actual_context_set(context, ignore_compiled=True) + for stub_context in stub_contexts: + for filter in stub_context.get_filters( + search_global=False, origin_scope=user_context.tree_node): + completion_names += filter.values() return completion_names def _get_importer_names(self, names, level=0, only_modules=True): diff --git a/test/completion/stubs.py b/test/completion/stubs.py index 2b8d164c..06c5d432 100644 --- a/test/completion/stubs.py +++ b/test/completion/stubs.py @@ -22,6 +22,11 @@ with_stub.in_with_stub_python #! ['in_with_stub_stub: float'] with_stub.in_with_stub_stub +#? ['in_stub_only'] +stub_only.in_ +#? ['in_with_stub_both', 'in_with_stub_python', 'in_with_stub_stub'] +with_stub.in_ + # ------------------------- # Folders # ------------------------- @@ -35,6 +40,11 @@ with_stub_folder.in_with_stub_python_folder #? float() with_stub_folder.in_with_stub_stub_folder +#? ['in_stub_only_folder'] +stub_only_folder.in_ +#? ['in_with_stub_both_folder', 'in_with_stub_python_folder', 'in_with_stub_stub_folder'] +with_stub_folder.in_ + # ------------------------- # Folders nested with stubs # ------------------------- @@ -53,6 +63,13 @@ nested_with_stub.in_stub #? str() python_only.in_python +#? ['in_stub_only_folder'] +stub_only_folder.in_ +#? ['in_with_stub_both_folder', 'in_with_stub_python_folder', 'in_with_stub_stub_folder'] +with_stub_folder.in_ +#? ['in_python'] +python_only.in_ + # ------------------------- # Folders nested with stubs # ------------------------- @@ -70,3 +87,10 @@ nested_with_stub.in_python nested_with_stub.in_stub #? str() python_only.in_python + +#? ['in_stub_only'] +nested_stub_only.in_ +#? ['in_both', 'in_python', 'in_stub'] +nested_with_stub.in_ +#? ['in_python'] +python_only.in_