diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index aa272310..c7abf2e0 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -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) diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index 8995adb1..5d1ccf39 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -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 diff --git a/test/test_api/test_call_signatures.py b/test/test_api/test_call_signatures.py index fb140c20..81d3c026 100644 --- a/test/test_api/test_call_signatures.py +++ b/test/test_api/test_call_signatures.py @@ -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)('))