mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-19 03:55:57 +08:00
Fix some goto issues.
This commit is contained in:
@@ -426,7 +426,7 @@ class Script(object):
|
|||||||
and d.start_pos == (0, 0):
|
and d.start_pos == (0, 0):
|
||||||
i = imports.ImportWrapper(self._evaluator, d.parent).follow(is_goto=True)
|
i = imports.ImportWrapper(self._evaluator, d.parent).follow(is_goto=True)
|
||||||
definitions.remove(d)
|
definitions.remove(d)
|
||||||
definitions |= follow_inexistent_imports(i)
|
definitions |= follow_inexistent_imports(i.names[-1])
|
||||||
return definitions
|
return definitions
|
||||||
|
|
||||||
goto_path = self._user_context.get_path_under_cursor()
|
goto_path = self._user_context.get_path_under_cursor()
|
||||||
@@ -449,7 +449,7 @@ class Script(object):
|
|||||||
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.
|
||||||
user_scope = self._parser.user_scope()
|
user_scope = self._parser.user_scope()
|
||||||
definitions = set([user_scope.name])
|
definitions = set([user_scope.name.names[-1]])
|
||||||
elif isinstance(user_stmt, pr.Import):
|
elif isinstance(user_stmt, pr.Import):
|
||||||
s, name_part = helpers.get_on_import_stmt(self._evaluator,
|
s, name_part = helpers.get_on_import_stmt(self._evaluator,
|
||||||
self._user_context, user_stmt)
|
self._user_context, user_stmt)
|
||||||
@@ -461,9 +461,9 @@ class Script(object):
|
|||||||
if add_import_name:
|
if add_import_name:
|
||||||
import_name = user_stmt.get_defined_names()
|
import_name = user_stmt.get_defined_names()
|
||||||
# imports have only one name
|
# imports have only one name
|
||||||
if not user_stmt.star \
|
np = import_name[0].names[-1]
|
||||||
and unicode(name_part) == unicode(import_name[0].names[-1]):
|
if not user_stmt.star and unicode(name_part) == unicode(np):
|
||||||
definitions.append(import_name[0])
|
definitions.append(np)
|
||||||
else:
|
else:
|
||||||
# The Evaluator.goto function checks for definitions, but since we
|
# The Evaluator.goto function checks for definitions, but since we
|
||||||
# use a reverse tokenizer, we have new name_part objects, so we
|
# use a reverse tokenizer, we have new name_part objects, so we
|
||||||
@@ -472,7 +472,7 @@ class Script(object):
|
|||||||
for name in user_stmt.get_defined_names():
|
for name in user_stmt.get_defined_names():
|
||||||
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 [name]
|
return [name.names[0]]
|
||||||
|
|
||||||
defs = self._evaluator.goto(stmt, call_path)
|
defs = self._evaluator.goto(stmt, call_path)
|
||||||
definitions = follow_inexistent_imports(defs)
|
definitions = follow_inexistent_imports(defs)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def defined_names(evaluator, scope):
|
|||||||
include_builtin=False), None)
|
include_builtin=False), None)
|
||||||
names = pair[1] if pair else []
|
names = pair[1] if pair else []
|
||||||
names = [n for n in names if isinstance(n, pr.Import) or (len(n) == 1)]
|
names = [n for n in names if isinstance(n, pr.Import) or (len(n) == 1)]
|
||||||
return [Definition(evaluator, d) for d in sorted(names, key=lambda s: s.start_pos)]
|
return [Definition(evaluator, d.names[-1]) for d in sorted(names, key=lambda s: s.start_pos)]
|
||||||
|
|
||||||
|
|
||||||
class BaseDefinition(object):
|
class BaseDefinition(object):
|
||||||
@@ -653,6 +653,8 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
d = d.var
|
d = d.var
|
||||||
if isinstance(d, (pr.Name, pr.NamePart)):
|
if isinstance(d, (pr.Name, pr.NamePart)):
|
||||||
d = d.get_definition()
|
d = d.get_definition()
|
||||||
|
if isinstance(d, er.InstanceElement):
|
||||||
|
d = d.var
|
||||||
|
|
||||||
if isinstance(d, compiled.CompiledObject):
|
if isinstance(d, compiled.CompiledObject):
|
||||||
typ = d.type()
|
typ = d.type()
|
||||||
@@ -707,6 +709,8 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
Returns True, if defined as a name in a statement, function or class.
|
Returns True, if defined as a name in a statement, function or class.
|
||||||
Returns False, if it's a reference to such a definition.
|
Returns False, if it's a reference to such a definition.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(self._definition, compiled.CompiledName):
|
||||||
|
return True
|
||||||
if not isinstance(self._definition, pr.NamePart):
|
if not isinstance(self._definition, pr.NamePart):
|
||||||
# Currently only handle NameParts. Once we have a proper API, this
|
# Currently only handle NameParts. Once we have a proper API, this
|
||||||
# will be the standard anyway.
|
# will be the standard anyway.
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ from jedi.evaluate import helpers
|
|||||||
|
|
||||||
|
|
||||||
def usages(evaluator, definitions, mods):
|
def usages(evaluator, definitions, mods):
|
||||||
|
"""
|
||||||
|
:param definitions: list of NameParts
|
||||||
|
"""
|
||||||
def compare_array(definitions):
|
def compare_array(definitions):
|
||||||
""" `definitions` are being compared by module/start_pos, because
|
""" `definitions` are being compared by module/start_pos, because
|
||||||
sometimes the id's of the objects change (e.g. executions).
|
sometimes the id's of the objects change (e.g. executions).
|
||||||
@@ -54,7 +57,7 @@ def usages(evaluator, definitions, mods):
|
|||||||
if any(r in compare_definitions for r in compare_follow_res):
|
if any(r in compare_definitions for r in compare_follow_res):
|
||||||
yield classes.Definition(evaluator, search)
|
yield classes.Definition(evaluator, search)
|
||||||
|
|
||||||
search_name = unicode(list(definitions)[0].names[-1])
|
search_name = unicode(list(definitions)[0])
|
||||||
compare_definitions = compare_array(definitions)
|
compare_definitions = compare_array(definitions)
|
||||||
mods |= set([d.get_parent_until() for d in definitions])
|
mods |= set([d.get_parent_until() for d in definitions])
|
||||||
names = []
|
names = []
|
||||||
|
|||||||
Reference in New Issue
Block a user