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,6 +445,13 @@ class Script(object):
if stmt is None:
return []
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]

View File

@@ -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

View File

@@ -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'):

View File

@@ -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:

View File

@@ -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