forked from VimPlug/jedi
Remove search_name and search_name_part from goto returns.
The search_name can be retrieved by checking definitions for it. Definitions should always be names or even better name_parts in case of goto. Therefore we can just get it there.
This commit is contained in:
@@ -401,7 +401,7 @@ class Script(object):
|
|||||||
|
|
||||||
:rtype: list of :class:`classes.Definition`
|
:rtype: list of :class:`classes.Definition`
|
||||||
"""
|
"""
|
||||||
results, _ = self._goto()
|
results = self._goto()
|
||||||
d = [classes.Definition(self._evaluator, d) for d in set(results)
|
d = [classes.Definition(self._evaluator, d) for d in set(results)
|
||||||
if d is not imports.ImportWrapper.GlobalNamespace]
|
if d is not imports.ImportWrapper.GlobalNamespace]
|
||||||
return helpers.sorted_definitions(d)
|
return helpers.sorted_definitions(d)
|
||||||
@@ -433,7 +433,6 @@ class Script(object):
|
|||||||
# 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])
|
||||||
search_name = unicode(user_scope.name)
|
|
||||||
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)
|
||||||
@@ -441,7 +440,6 @@ class Script(object):
|
|||||||
definitions = [s.follow(is_goto=True)[0]]
|
definitions = [s.follow(is_goto=True)[0]]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
definitions = []
|
definitions = []
|
||||||
search_name = unicode(name_part)
|
|
||||||
|
|
||||||
if add_import_name:
|
if add_import_name:
|
||||||
import_name = user_stmt.get_defined_names()
|
import_name = user_stmt.get_defined_names()
|
||||||
@@ -461,14 +459,14 @@ 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, unicode(name.names[-1])
|
return name
|
||||||
return None, None
|
return None
|
||||||
|
|
||||||
lhs, search_name = test_lhs()
|
lhs = test_lhs()
|
||||||
if lhs is None:
|
if lhs is None:
|
||||||
expression_list = stmt.expression_list()
|
expression_list = stmt.expression_list()
|
||||||
if len(expression_list) == 0:
|
if len(expression_list) == 0:
|
||||||
return [], ''
|
return []
|
||||||
# The reverse tokenizer only generates parses call.
|
# The reverse tokenizer only generates parses call.
|
||||||
assert len(expression_list) == 1
|
assert len(expression_list) == 1
|
||||||
call = expression_list[0]
|
call = expression_list[0]
|
||||||
@@ -476,15 +474,14 @@ class Script(object):
|
|||||||
call_path = list(call.generate_call_path())
|
call_path = list(call.generate_call_path())
|
||||||
else:
|
else:
|
||||||
# goto_assignments on Operator returns nothing.
|
# goto_assignments on Operator returns nothing.
|
||||||
return [], search_name
|
return []
|
||||||
|
|
||||||
defs, search_name_part = self._evaluator.goto(user_stmt or stmt,
|
defs = self._evaluator.goto(user_stmt or stmt,
|
||||||
call_path)
|
call_path)
|
||||||
search_name = unicode(search_name_part)
|
|
||||||
definitions = follow_inexistent_imports(defs)
|
definitions = follow_inexistent_imports(defs)
|
||||||
else:
|
else:
|
||||||
definitions = [lhs]
|
definitions = [lhs]
|
||||||
return definitions, search_name
|
return definitions
|
||||||
|
|
||||||
def usages(self, additional_module_paths=()):
|
def usages(self, additional_module_paths=()):
|
||||||
"""
|
"""
|
||||||
@@ -501,7 +498,7 @@ class Script(object):
|
|||||||
settings.dynamic_flow_information, False
|
settings.dynamic_flow_information, False
|
||||||
try:
|
try:
|
||||||
user_stmt = self._parser.user_stmt()
|
user_stmt = self._parser.user_stmt()
|
||||||
definitions, search_name = self._goto(add_import_name=True)
|
definitions = self._goto(add_import_name=True)
|
||||||
if not definitions:
|
if not definitions:
|
||||||
# Without a definition for a name we cannot find references.
|
# Without a definition for a name we cannot find references.
|
||||||
return []
|
return []
|
||||||
@@ -523,7 +520,7 @@ class Script(object):
|
|||||||
|
|
||||||
module = set([d.get_parent_until() for d in definitions])
|
module = set([d.get_parent_until() for d in definitions])
|
||||||
module.add(self._parser.module())
|
module.add(self._parser.module())
|
||||||
names = usages.usages(self._evaluator, definitions, search_name, module)
|
names = usages.usages(self._evaluator, definitions, module)
|
||||||
|
|
||||||
for d in set(definitions):
|
for d in set(definitions):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ class BaseDefinition(object):
|
|||||||
return [self]
|
return [self]
|
||||||
stmt_or_imp = self._definition.get_parent_until((pr.Statement, pr.Import))
|
stmt_or_imp = self._definition.get_parent_until((pr.Statement, pr.Import))
|
||||||
call_path = call_path_for_name_part(stmt_or_imp, self._definition)
|
call_path = call_path_for_name_part(stmt_or_imp, self._definition)
|
||||||
names, _ = self._evaluator.goto(stmt_or_imp, call_path)
|
names = self._evaluator.goto(stmt_or_imp, call_path)
|
||||||
return [Definition(self._evaluator, n) for n in names]
|
return [Definition(self._evaluator, n) for n in names]
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from jedi.evaluate import imports
|
|||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
|
|
||||||
|
|
||||||
def usages(evaluator, definitions, search_name, mods):
|
def usages(evaluator, definitions, mods):
|
||||||
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).
|
||||||
@@ -37,7 +37,8 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
follow.append(call_path[:i + 1])
|
follow.append(call_path[:i + 1])
|
||||||
|
|
||||||
for call_path in follow:
|
for call_path in follow:
|
||||||
follow_res, search = evaluator.goto(call.parent, call_path)
|
follow_res = evaluator.goto(call.parent, call_path)
|
||||||
|
search = call_path[-1]
|
||||||
# names can change (getattr stuff), therefore filter names that
|
# names can change (getattr stuff), therefore filter names that
|
||||||
# don't match `search`.
|
# don't match `search`.
|
||||||
|
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ class Evaluator(object):
|
|||||||
for s in scopes:
|
for s in scopes:
|
||||||
follow_res += self.find_types(s, search_name_part, pos,
|
follow_res += self.find_types(s, search_name_part, pos,
|
||||||
search_global=search_global, is_goto=True)
|
search_global=search_global, is_goto=True)
|
||||||
return follow_res, search_name_part
|
return follow_res
|
||||||
|
|
||||||
|
|
||||||
def filter_private_variable(scope, call_scope, var_name):
|
def filter_private_variable(scope, call_scope, var_name):
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def _get_calling_var_args(evaluator, var_args):
|
|||||||
if len(exp_list) != 2 or exp_list[0] not in ('*', '**'):
|
if len(exp_list) != 2 or exp_list[0] not in ('*', '**'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
names, _ = evaluator.goto(argument, [exp_list[1].get_code()])
|
names = evaluator.goto(argument, [exp_list[1].get_code()])
|
||||||
if len(names) != 1:
|
if len(names) != 1:
|
||||||
break
|
break
|
||||||
param = names[0].parent
|
param = names[0].parent
|
||||||
|
|||||||
Reference in New Issue
Block a user