forked from VimPlug/jedi
Some goto refactorings.
This commit is contained in:
+20
-19
@@ -458,21 +458,22 @@ class Evaluator(object):
|
|||||||
def goto(self, name):
|
def goto(self, name):
|
||||||
def resolve_implicit_imports(names):
|
def resolve_implicit_imports(names):
|
||||||
for name in names:
|
for name in names:
|
||||||
if isinstance(name, helpers.FakeName):
|
if isinstance(name.parent, helpers.FakeImport):
|
||||||
# Those are implicit imports.
|
# Those are implicit imports.
|
||||||
s = imports.ImportWrapper(self, name)
|
s = imports.ImportWrapper(self, name)
|
||||||
for n in s.follow(is_goto=True):
|
for n in s.follow(is_goto=True):
|
||||||
yield n
|
yield n
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
imp = name.get_definition()
|
stmt = name.get_definition()
|
||||||
stmt = name.parent
|
# Only take the parent, because if it's more complicated than just a
|
||||||
if isinstance(stmt, pr.ExprStmt) and name in stmt.get_defined_names():
|
# name it's something you can "goto" again.
|
||||||
# TODO remove? I think this is never called.
|
par = name.parent
|
||||||
|
if isinstance(par, pr.ExprStmt) and name in par.get_defined_names():
|
||||||
return [name]
|
return [name]
|
||||||
elif isinstance(stmt, (pr.Param, pr.Function, pr.Class)) and stmt.name is name:
|
elif isinstance(par, (pr.Param, pr.Function, pr.Class)) and par.name is name:
|
||||||
return [name]
|
return [name]
|
||||||
elif isinstance(imp, pr.Import):
|
elif isinstance(stmt, pr.Import):
|
||||||
return imports.ImportWrapper(self, name).follow(is_goto=True)
|
return imports.ImportWrapper(self, name).follow(is_goto=True)
|
||||||
|
|
||||||
scope = name.get_parent_scope()
|
scope = name.get_parent_scope()
|
||||||
@@ -487,17 +488,17 @@ class Evaluator(object):
|
|||||||
search_global=True, is_goto=True)
|
search_global=True, is_goto=True)
|
||||||
|
|
||||||
|
|
||||||
if isinstance(stmt, pr.Import):
|
if isinstance(par, pr.Import):
|
||||||
# Nowhere to goto for aliases
|
# Nowhere to goto for aliases
|
||||||
if stmt.alias == call_path[0]:
|
if par.alias == call_path[0]:
|
||||||
return [call_path[0]]
|
return [call_path[0]]
|
||||||
|
|
||||||
names = stmt.get_all_import_names()
|
names = par.get_all_import_names()
|
||||||
if stmt.alias:
|
if par.alias:
|
||||||
names = names[:-1]
|
names = names[:-1]
|
||||||
# Filter names that are after our Name
|
# Filter names that are after our Name
|
||||||
removed_names = len(names) - names.index(call_path[0]) - 1
|
removed_names = len(names) - names.index(call_path[0]) - 1
|
||||||
i = imports.ImportWrapper(self, stmt, kill_count=removed_names,
|
i = imports.ImportWrapper(self, par, kill_count=removed_names,
|
||||||
nested_resolve=True)
|
nested_resolve=True)
|
||||||
return i.follow(is_goto=True)
|
return i.follow(is_goto=True)
|
||||||
|
|
||||||
@@ -506,17 +507,17 @@ class Evaluator(object):
|
|||||||
# name only. Otherwise it's a mixture between a definition and a
|
# name only. Otherwise it's a mixture between a definition and a
|
||||||
# reference. In this case it's just a definition. So we stay on it.
|
# reference. In this case it's just a definition. So we stay on it.
|
||||||
if len(call_path) == 1 and isinstance(call_path[0], pr.Name) \
|
if len(call_path) == 1 and isinstance(call_path[0], pr.Name) \
|
||||||
and call_path[0] in stmt.get_defined_names():
|
and call_path[0] in par.get_defined_names():
|
||||||
# Named params should get resolved to their param definitions.
|
# Named params should get resolved to their param definitions.
|
||||||
if pr.Array.is_type(stmt.parent, pr.Array.TUPLE, pr.Array.NOARRAY) \
|
if pr.Array.is_type(par.parent, pr.Array.TUPLE, pr.Array.NOARRAY) \
|
||||||
and stmt.parent.previous:
|
and par.parent.previous:
|
||||||
call = deep_ast_copy(stmt.parent.previous)
|
call = deep_ast_copy(par.parent.previous)
|
||||||
# We have made a copy, so we're fine to change it.
|
# We have made a copy, so we're fine to change it.
|
||||||
call.next = None
|
call.next = None
|
||||||
while call.previous is not None:
|
while call.previous is not None:
|
||||||
call = call.previous
|
call = call.previous
|
||||||
param_names = []
|
param_names = []
|
||||||
named_param_name = stmt.get_defined_names()[0]
|
named_param_name = par.get_defined_names()[0]
|
||||||
for typ in self.eval_call(call):
|
for typ in self.eval_call(call):
|
||||||
if isinstance(typ, er.Class):
|
if isinstance(typ, er.Class):
|
||||||
params = []
|
params = []
|
||||||
@@ -530,8 +531,8 @@ class Evaluator(object):
|
|||||||
return param_names
|
return param_names
|
||||||
return [call_path[0]]
|
return [call_path[0]]
|
||||||
|
|
||||||
scope = stmt.get_parent_scope()
|
scope = par.get_parent_scope()
|
||||||
pos = stmt.start_pos
|
pos = par.start_pos
|
||||||
first_part, search_name_part = call_path[:-1], call_path[-1]
|
first_part, search_name_part = call_path[:-1], call_path[-1]
|
||||||
|
|
||||||
if first_part:
|
if first_part:
|
||||||
|
|||||||
Reference in New Issue
Block a user