From c809aad67f93b153fb9cedf9fa0e3b637fa3ae7f Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Sat, 4 Feb 2017 12:58:54 +0100 Subject: [PATCH] Complete dotted names properly in decorators Outside decorators, a dotted name is parsed by the grammar as stmt -> test -> power -> atom trailer -> (NAME) ('.' NAME) where the first NAME is an 'atom' and the second NAME is a 'trailer'. Thus, testing if the most recent variable is a 'trailer' and the most recent node is a '.' is almost always enough for Jedi to properly complete dotted names. However, the grammar for decorators is more restricted and doesn't allow arbitrary atoms and trailers; instead, a dotted name in a decorator is decorator -> '@' dotted_name -> '@' (NAME '.' NAME), meaning the most recent variable will be 'dotted_name', not 'trailer'. Besides in decorators, the 'dotted_name' variable is only used in import statements which are handled previously in _get_context_completions, so checking for 'dotted_name' in this arm of the if only covers decorators and not inadvertently anything else. --- jedi/api/completion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jedi/api/completion.py b/jedi/api/completion.py index 9cb569a2..f18815f9 100644 --- a/jedi/api/completion.py +++ b/jedi/api/completion.py @@ -164,7 +164,7 @@ class Completion: # No completions for ``with x as foo`` and ``import x as foo``. # Also true for defining names as a class or function. return list(self._get_class_context_completions(is_function=True)) - elif symbol_names[-1] == 'trailer' and nodes[-1] == '.': + elif symbol_names[-1] in ('trailer', 'dotted_name') and nodes[-1] == '.': dot = self._module_node.get_leaf_for_position(self._position) completion_names += self._trailer_completions(dot.get_previous_leaf()) else: