1
0
forked from VimPlug/jedi

Goto should work on named params, too.

This commit is contained in:
Dave Halter
2014-09-09 16:48:53 +02:00
parent 110f130741
commit 87aa76678a
2 changed files with 18 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ from jedi.evaluate import stdlib
from jedi.evaluate import finder
from jedi.evaluate import compiled
from jedi.evaluate import precedence
from jedi.evaluate.helpers import FakeStatement
from jedi.evaluate.helpers import FakeStatement, deep_ast_copy
class Evaluator(object):
@@ -326,6 +326,21 @@ class Evaluator(object):
# 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.NamePart) \
and call_path[0] in [d.names[-1] for d in stmt.get_defined_names()]:
# Named params should get resolved to their param defintions.
if pr.Array.is_type(stmt.parent, pr.Array.TUPLE, pr.Array.NOARRAY) \
and stmt.parent.previous:
call = deep_ast_copy(stmt.parent.previous)
# We have made a copy, so we're fine to change it.
call.next = None
while call.previous is not None:
call = call.previous
param_names = []
named_param_name = stmt.get_defined_names()[0]
for typ in self.eval_call(call):
for param in typ.params:
if unicode(param.get_name()) == unicode(named_param_name):
param_names.append(param.get_name())
return param_names
return [call_path[0]]
scope = stmt.get_parent_scope()

View File

@@ -211,11 +211,11 @@ class TestGotoAssignments(TestCase):
def test_named_params(self):
src = """\
def foo(bar):
def foo(a=1, bar=2):
pass
foo(bar=1)
"""
bar = names(dedent(src), references=True)[-1]
param = bar.goto_assignments()[0]
assert param.start_pos == (1, 9)
assert param.start_pos == (1, 13)
assert param.type == 'param'