Usages are pretty solid now except for parser issues.

This commit is contained in:
Dave Halter
2014-11-22 15:43:23 +01:00
parent b82e1e28e5
commit f1cbd45575
5 changed files with 25 additions and 9 deletions

View File

@@ -445,9 +445,16 @@ class Script(object):
if stmt is None: if stmt is None:
return [] return []
last_name = stmt if user_stmt is None:
while not isinstance(last_name, pr.Name): last_name = None
last_name = last_name.children[-1] 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'): if next(context) in ('class', 'def'):
# The cursor is on a class/function name. # The cursor is on a class/function name.

View File

@@ -68,7 +68,7 @@ def usages(evaluator, definition_names, mods):
for name in check_names: for name in check_names:
result = evaluator.goto(name) 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)) definitions.append(classes.Definition(evaluator, name))
continue # TODO DELETE continue # TODO DELETE

View File

@@ -446,6 +446,8 @@ class Evaluator(object):
stmt = name.parent stmt = name.parent
if isinstance(stmt, pr.ExprStmt) and name in stmt.get_defined_names(): if isinstance(stmt, pr.ExprStmt) and name in stmt.get_defined_names():
return [name] return [name]
elif isinstance(stmt, (pr.Param, pr.Function, pr.Class)) and stmt.name is name:
return [name]
scope = name.get_parent_scope() scope = name.get_parent_scope()
if pr.is_node(name.parent, 'trailer'): if pr.is_node(name.parent, 'trailer'):

View File

@@ -1456,6 +1456,11 @@ class Param(Base):
return self.tfpdef.start_pos return self.tfpdef.start_pos
def get_name(self): def get_name(self):
# TODO remove!
return self.name
@property
def name(self):
if is_node(self.tfpdef, 'tfpdef'): if is_node(self.tfpdef, 'tfpdef'):
return self.tfpdef.children[0] return self.tfpdef.children[0]
else: else:

View File

@@ -13,16 +13,18 @@ abc
# unicode chars shouldn't be a problem. # unicode chars shouldn't be a problem.
x['smörbröd'].abc x['smörbröd'].abc
# With the new parser these statements are not recognized as stateents, because
# they are not valid Python.
if 1: if 1:
abc = abc =
else: else:
(abc) = (abc) =
abc = abc =
#< (-17,4), (-14,0), (-12,0), (0,0)
#< (-3,0), (0,0)
abc abc
abc = 5
Abc = 3 Abc = 3
@@ -48,11 +50,11 @@ Abc.d.Abc
#< 4 (0,4), (4,1) #< 4 (0,4), (4,1)
def blub(): def blubi():
#< (-4,4), (0,1) #< (-4,4), (0,1)
@blub @blubi
def a(): pass def a(): pass