mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
goto_assignments and usages both working now with issues like #315
This commit is contained in:
@@ -249,12 +249,12 @@ class Script(object):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
raise NotFoundError()
|
raise NotFoundError()
|
||||||
user_stmt = self._parser.user_stmt()
|
user_stmt = self._parser.user_stmt()
|
||||||
if type(user_stmt) is pr.Statement:
|
if user_stmt is None:
|
||||||
stmt.start_pos = user_stmt.start_pos
|
|
||||||
else:
|
|
||||||
# Set the start_pos to a pseudo position, that doesn't exist but works
|
# Set the start_pos to a pseudo position, that doesn't exist but works
|
||||||
# perfectly well (for both completions in docstrings and statements).
|
# perfectly well (for both completions in docstrings and statements).
|
||||||
stmt.start_pos = self._pos
|
stmt.start_pos = self._pos
|
||||||
|
else:
|
||||||
|
stmt.start_pos = user_stmt.start_pos
|
||||||
stmt.parent = self._parser.user_scope()
|
stmt.parent = self._parser.user_scope()
|
||||||
return stmt
|
return stmt
|
||||||
|
|
||||||
@@ -437,7 +437,7 @@ class Script(object):
|
|||||||
for name in user_stmt.get_set_vars():
|
for name in user_stmt.get_set_vars():
|
||||||
if name.start_pos <= self._pos <= name.end_pos \
|
if name.start_pos <= self._pos <= name.end_pos \
|
||||||
and len(name.names) == 1:
|
and len(name.names) == 1:
|
||||||
return user_stmt, name.names[-1]
|
return name, name.names[-1]
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
lhs, search_name = test_lhs()
|
lhs, search_name = test_lhs()
|
||||||
|
|||||||
@@ -36,8 +36,18 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
result.append((module, d.start_pos))
|
result.append((module, d.start_pos))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def check_call(call):
|
def check_call_for_usage(call):
|
||||||
result = []
|
stmt = call.parent
|
||||||
|
while not isinstance(stmt.parent, pr.IsScope):
|
||||||
|
stmt = stmt.parent
|
||||||
|
# New definition, call cannot be a part of stmt
|
||||||
|
if len(call.name) == 1 and call.execution is None \
|
||||||
|
and call.name in stmt.get_set_vars():
|
||||||
|
# Class params are not definitions (like function params). They
|
||||||
|
# are super classes, that need to be resolved.
|
||||||
|
if not (isinstance(stmt, pr.Param) and isinstance(stmt.parent, pr.Class)):
|
||||||
|
return
|
||||||
|
|
||||||
follow = [] # There might be multiple search_name's in one call_path
|
follow = [] # There might be multiple search_name's in one call_path
|
||||||
call_path = list(call.generate_call_path())
|
call_path = list(call.generate_call_path())
|
||||||
for i, name in enumerate(call_path):
|
for i, name in enumerate(call_path):
|
||||||
@@ -45,10 +55,10 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
if name == search_name:
|
if name == search_name:
|
||||||
follow.append(call_path[:i + 1])
|
follow.append(call_path[:i + 1])
|
||||||
|
|
||||||
for f in follow:
|
for call_path in follow:
|
||||||
follow_res, search = evaluator.goto(call.parent, f)
|
follow_res, search = evaluator.goto(call.parent, call_path)
|
||||||
# names can change (getattr stuff), therefore filter names that
|
# names can change (getattr stuff), therefore filter names that
|
||||||
# don't match `search_name`.
|
# don't match `search`.
|
||||||
|
|
||||||
# TODO add something like that in the future - for now usages are
|
# TODO add something like that in the future - for now usages are
|
||||||
# completely broken anyway.
|
# completely broken anyway.
|
||||||
@@ -61,9 +71,7 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
# compare to see if they match
|
# compare to see if they match
|
||||||
if any(r in compare_definitions for r in compare_follow_res):
|
if any(r in compare_definitions for r in compare_follow_res):
|
||||||
scope = call.parent
|
scope = call.parent
|
||||||
result.append(Usage(evaluator, search, scope))
|
yield Usage(evaluator, search, scope)
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
if not definitions:
|
if not definitions:
|
||||||
return set()
|
return set()
|
||||||
@@ -94,7 +102,7 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
names.append(Usage(evaluator, name_part, stmt))
|
names.append(Usage(evaluator, name_part, stmt))
|
||||||
else:
|
else:
|
||||||
for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True):
|
for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True):
|
||||||
names += check_call(call)
|
names += check_call_for_usage(call)
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ abc.d.a.bsaasd.abc.d
|
|||||||
|
|
||||||
abc
|
abc
|
||||||
|
|
||||||
|
if 1:
|
||||||
|
abc =
|
||||||
|
else:
|
||||||
|
(abc) =
|
||||||
|
|
||||||
abc =
|
abc =
|
||||||
|
|
||||||
#< (-3,0), (0,0)
|
#< (-3,0), (0,0)
|
||||||
|
|||||||
Reference in New Issue
Block a user