mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Add new tests and certain fixes for some new call signature issues.
This commit is contained in:
@@ -6,7 +6,7 @@ from collections import namedtuple
|
||||
|
||||
from jedi import common
|
||||
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.parser import tokenize, token
|
||||
|
||||
@@ -181,9 +181,7 @@ def evaluate_goto_definition(evaluator, leaf):
|
||||
if parent.type == 'atom':
|
||||
node = leaf.parent
|
||||
elif parent.type == 'trailer':
|
||||
index = parent.parent.children.index(parent)
|
||||
node = deep_ast_copy(parent.parent)
|
||||
node.children = node.children[:index + 1]
|
||||
node = call_of_name(leaf)
|
||||
|
||||
if node is None:
|
||||
return []
|
||||
@@ -225,7 +223,7 @@ def _get_call_signature_details_from_error_node(node, position):
|
||||
# until the parentheses is enough.
|
||||
children = node.children[index:]
|
||||
name = element.get_previous_leaf()
|
||||
if name.type == 'name':
|
||||
if name.type == 'name' or name.parent.type == 'trailer':
|
||||
return CallSignatureDetails(
|
||||
element,
|
||||
*_get_index_and_key(children, position)
|
||||
|
||||
@@ -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?
|
||||
"""
|
||||
trailer = name.parent
|
||||
if trailer.type != 'trailer' or trailer.children[0] != '.':
|
||||
if trailer.type != 'trailer':
|
||||
return name
|
||||
|
||||
assert not cut_own_trailer # TODO remove
|
||||
|
||||
@@ -356,3 +356,16 @@ def test_bracket_start():
|
||||
return signatures[0].bracket_start
|
||||
|
||||
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)('))
|
||||
|
||||
Reference in New Issue
Block a user