From f1cbd45575971ab3879f04e764be7da35e69e2fc Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 22 Nov 2014 15:43:23 +0100 Subject: [PATCH] Usages are pretty solid now except for parser issues. --- jedi/api/__init__.py | 13 ++++++++++--- jedi/api/usages.py | 2 +- jedi/evaluate/__init__.py | 2 ++ jedi/parser/representation.py | 5 +++++ test/completion/usages.py | 12 +++++++----- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 21d8fd92..37d5ea94 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -445,9 +445,16 @@ class Script(object): if stmt is None: return [] - last_name = stmt - while not isinstance(last_name, pr.Name): - last_name = last_name.children[-1] + if user_stmt is None: + last_name = None + else: + # Try to use the parser if possible. + last_name = user_stmt.name_for_position(self._pos) + + if last_name is None: + last_name = stmt + while not isinstance(last_name, pr.Name): + last_name = last_name.children[-1] if next(context) in ('class', 'def'): # The cursor is on a class/function name. diff --git a/jedi/api/usages.py b/jedi/api/usages.py index 6d4dec6f..0ea3d459 100644 --- a/jedi/api/usages.py +++ b/jedi/api/usages.py @@ -68,7 +68,7 @@ def usages(evaluator, definition_names, mods): for name in check_names: result = evaluator.goto(name) - if [c in compare_definitions for c in compare_array(result)]: + if [c for c in compare_array(result) if c in compare_definitions]: definitions.append(classes.Definition(evaluator, name)) continue # TODO DELETE diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 1fa41836..3f0a22d0 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -446,6 +446,8 @@ class Evaluator(object): stmt = name.parent if isinstance(stmt, pr.ExprStmt) and name in stmt.get_defined_names(): return [name] + elif isinstance(stmt, (pr.Param, pr.Function, pr.Class)) and stmt.name is name: + return [name] scope = name.get_parent_scope() if pr.is_node(name.parent, 'trailer'): diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 1134c0f0..ea5bd01f 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -1456,6 +1456,11 @@ class Param(Base): return self.tfpdef.start_pos def get_name(self): + # TODO remove! + return self.name + + @property + def name(self): if is_node(self.tfpdef, 'tfpdef'): return self.tfpdef.children[0] else: diff --git a/test/completion/usages.py b/test/completion/usages.py index a4c285b3..6f835f69 100644 --- a/test/completion/usages.py +++ b/test/completion/usages.py @@ -13,16 +13,18 @@ abc # unicode chars shouldn't be a problem. x['smörbröd'].abc +# With the new parser these statements are not recognized as stateents, because +# they are not valid Python. if 1: abc = else: (abc) = - abc = - -#< (-3,0), (0,0) +#< (-17,4), (-14,0), (-12,0), (0,0) abc +abc = 5 + Abc = 3 @@ -48,11 +50,11 @@ Abc.d.Abc #< 4 (0,4), (4,1) -def blub(): +def blubi(): #< (-4,4), (0,1) -@blub +@blubi def a(): pass