1
0
forked from VimPlug/jedi

Add new tests and certain fixes for some new call signature issues.

This commit is contained in:
Dave Halter
2016-06-20 18:20:35 +02:00
parent b9d3371f39
commit e0631cfda2
3 changed files with 17 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ from collections import namedtuple
from jedi import common from jedi import common
from jedi.evaluate import imports from jedi.evaluate import imports
from jedi.evaluate.helpers import deep_ast_copy from jedi.evaluate.helpers import deep_ast_copy, call_of_name
from jedi import parser from jedi import parser
from jedi.parser import tokenize, token from jedi.parser import tokenize, token
@@ -181,9 +181,7 @@ def evaluate_goto_definition(evaluator, leaf):
if parent.type == 'atom': if parent.type == 'atom':
node = leaf.parent node = leaf.parent
elif parent.type == 'trailer': elif parent.type == 'trailer':
index = parent.parent.children.index(parent) node = call_of_name(leaf)
node = deep_ast_copy(parent.parent)
node.children = node.children[:index + 1]
if node is None: if node is None:
return [] return []
@@ -225,7 +223,7 @@ def _get_call_signature_details_from_error_node(node, position):
# until the parentheses is enough. # until the parentheses is enough.
children = node.children[index:] children = node.children[index:]
name = element.get_previous_leaf() name = element.get_previous_leaf()
if name.type == 'name': if name.type == 'name' or name.parent.type == 'trailer':
return CallSignatureDetails( return CallSignatureDetails(
element, element,
*_get_index_and_key(children, position) *_get_index_and_key(children, position)

View File

@@ -82,7 +82,7 @@ def call_of_name(name, cut_own_trailer=False):
# ignore it, It's not what we want anyway. Or document it better? # ignore it, It's not what we want anyway. Or document it better?
""" """
trailer = name.parent trailer = name.parent
if trailer.type != 'trailer' or trailer.children[0] != '.': if trailer.type != 'trailer':
return name return name
assert not cut_own_trailer # TODO remove assert not cut_own_trailer # TODO remove

View File

@@ -356,3 +356,16 @@ def test_bracket_start():
return signatures[0].bracket_start return signatures[0].bracket_start
assert bracket_start('str(') == (1, 3) assert bracket_start('str(') == (1, 3)
def test_different_caller():
"""
It's possible to not use names, but another function result or an array
index and then get the call signature of it.
"""
assert_signature('[str][0](', 'str', 0)
assert_signature('[str][0]()', 'str', 0, column=len('[str][0]('))
assert_signature('(str)(', 'str', 0)
assert_signature('(str)()', 'str', 0, column=len('(str)('))