From f46f00bc71e747d3fc5ed1dbf22e7ee5ecfe02e9 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 3 Dec 2019 22:12:33 +0100 Subject: [PATCH] Avoid wrong random call signature completion, fixes #1433 --- jedi/api/completion.py | 10 +++++++++- jedi/inference/compiled/__init__.py | 2 +- test/completion/named_param.py | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/jedi/api/completion.py b/jedi/api/completion.py index 88080193..75ce10e1 100644 --- a/jedi/api/completion.py +++ b/jedi/api/completion.py @@ -210,7 +210,15 @@ class Completion: completion_names += self._global_completions() completion_names += self._get_class_value_completions(is_function=False) - if 'trailer' in nonterminals: + # Apparently this looks like it's good enough to filter most cases + # so that signature completions don't randomly appear. + # To understand why this works, two things are important: + # 1. trailer with a `,` in it is either a subscript or an arglist. + # 2. If there's no `,`, it's at the start and only signatures start + # with `(`. Other trailers could start with `.` or `[`. + # One thing that might not work is completion in decorator + # executions, but most people won't care about that. + if nodes[-1] in ['(', ','] and nonterminals[-1] in ('trailer', 'arglist'): call_signatures = self._call_signatures_callback() completion_names += get_call_signature_param_names(call_signatures) diff --git a/jedi/inference/compiled/__init__.py b/jedi/inference/compiled/__init__.py index beef9523..0b87e891 100644 --- a/jedi/inference/compiled/__init__.py +++ b/jedi/inference/compiled/__init__.py @@ -1,7 +1,7 @@ from jedi._compatibility import unicode from jedi.inference.compiled.value import CompiledObject, CompiledName, \ CompiledObjectFilter, CompiledValueName, create_from_access_path -from jedi.inference.base_value import ValueWrapper, LazyValueWrapper +from jedi.inference.base_value import LazyValueWrapper def builtin_from_name(inference_state, string): diff --git a/test/completion/named_param.py b/test/completion/named_param.py index 66ba59e9..3bd27ece 100644 --- a/test/completion/named_param.py +++ b/test/completion/named_param.py @@ -60,3 +60,23 @@ Test().test(blub=) #? 12 [] any(iterable=) + + +def foo(xyz): + pass + +#? 7 ['xyz'] +foo(xyz) +# No completion should be possible if it's not a simple name +#? 17 [] +x = " "; foo(x.xyz) +#? 17 [] +x = " "; foo([xyz) +#? 20 [] +x = " "; foo(z[f,xyz) +#? 18 [] +x = " "; foo(z[xyz) +#? 20 [] +x = " "; foo(xyz[xyz) +#? 20 [] +x = " "; foo(xyz[(xyz)