1
0
forked from VimPlug/jedi

First small implementation of goto.

This commit is contained in:
Dave Halter
2014-11-21 14:21:00 +01:00
parent fd16dfe2c7
commit f604066288
3 changed files with 23 additions and 16 deletions

View File

@@ -442,7 +442,15 @@ class Evaluator(object):
call = call_of_name(name)
return self.eval_element(call)
def goto(self, stmt, call_path):
def goto(self, name):
scope = name.get_parent_scope()
if pr.is_node(name.parent, 'trailer'):
call = call_of_name(name, cut_own_trailer=True)
types = self.eval_element(call)
return iterable.unite(self.find_types(typ, name, is_goto=True)
for typ in types)
else:
return self.find_types(scope, name, search_global=True, is_goto=True)
if isinstance(stmt, pr.Import):
# Nowhere to goto for aliases
if stmt.alias == call_path[0]:

View File

@@ -97,7 +97,7 @@ def deep_ast_copy(obj, new_elements_default=None):
return recursion(obj)
def call_of_name(name):
def call_of_name(name, cut_own_trailer=False):
"""
Creates a "call" node that consist of all ``trailer`` and ``power``
objects. E.g. if you call it with ``append``::
@@ -119,10 +119,14 @@ def call_of_name(name):
par = power
# Now the name must be part of a trailer
index = par.children.index(name.parent)
if index != len(par.children) - 1:
if index != len(par.children) - 1 or cut_own_trailer:
# Now we have to cut the other trailers away.
par = deep_ast_copy(par)
par.children[index + 1:] = []
if not cut_own_trailer:
# Normally we would remove just the stuff after the index, but
# if the option is set remove the index as well. (for goto)
index = index + 1
par.children[index:] = []
return par