mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix some error node handling for call signatures
This commit is contained in:
@@ -254,7 +254,7 @@ def _iter_arguments(nodes, position):
|
|||||||
yield 0, remove_after_pos(first_leaf), False
|
yield 0, remove_after_pos(first_leaf), False
|
||||||
else:
|
else:
|
||||||
yield 0, None, False
|
yield 0, None, False
|
||||||
elif node == ',':
|
elif isinstance(node, tree.PythonLeaf) and node.value == ',':
|
||||||
if not previous_node_yielded:
|
if not previous_node_yielded:
|
||||||
yield 0, '', False
|
yield 0, '', False
|
||||||
previous_node_yielded = False
|
previous_node_yielded = False
|
||||||
@@ -294,7 +294,7 @@ def _get_index_and_key(nodes, position):
|
|||||||
return nodes_before.count(','), key_str
|
return nodes_before.count(','), key_str
|
||||||
|
|
||||||
|
|
||||||
def _get_call_signature_details_from_error_node(node, position):
|
def _get_call_signature_details_from_error_node(node, additional_children, position):
|
||||||
for index, element in reversed(list(enumerate(node.children))):
|
for index, element in reversed(list(enumerate(node.children))):
|
||||||
# `index > 0` means that it's a trailer and not an atom.
|
# `index > 0` means that it's a trailer and not an atom.
|
||||||
if element == '(' and element.end_pos <= position and index > 0:
|
if element == '(' and element.end_pos <= position and index > 0:
|
||||||
@@ -305,7 +305,7 @@ def _get_call_signature_details_from_error_node(node, position):
|
|||||||
if name is None:
|
if name is None:
|
||||||
continue
|
continue
|
||||||
if name.type == 'name' or name.parent.type in ('trailer', 'atom'):
|
if name.type == 'name' or name.parent.type in ('trailer', 'atom'):
|
||||||
return CallDetails(element, children, position)
|
return CallDetails(element, children + additional_children, position)
|
||||||
|
|
||||||
|
|
||||||
def get_call_signature_details(module, position):
|
def get_call_signature_details(module, position):
|
||||||
@@ -330,11 +330,16 @@ def get_call_signature_details(module, position):
|
|||||||
# makes it feel strange to have a call signature.
|
# makes it feel strange to have a call signature.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for n in node.children[::-1]:
|
additional_children = []
|
||||||
if n.start_pos < position and n.type == 'error_node':
|
for n in reversed(node.children):
|
||||||
result = _get_call_signature_details_from_error_node(n, position)
|
if n.start_pos < position:
|
||||||
|
if n.type == 'error_node':
|
||||||
|
result = _get_call_signature_details_from_error_node(
|
||||||
|
n, additional_children, position
|
||||||
|
)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
|
additional_children.append(n)
|
||||||
|
|
||||||
if node.type == 'trailer' and node.children[0] == '(':
|
if node.type == 'trailer' and node.children[0] == '(':
|
||||||
leaf = node.get_previous_leaf()
|
leaf = node.get_previous_leaf()
|
||||||
|
|||||||
@@ -457,13 +457,13 @@ code4 = 'def i(u, /, v, *args, x=1, y, **kwargs): pass'
|
|||||||
(code4, 'i(a,b,c,d,e', 2),
|
(code4, 'i(a,b,c,d,e', 2),
|
||||||
(code4, 'i(a,b,c,d,e=', 5),
|
(code4, 'i(a,b,c,d,e=', 5),
|
||||||
(code4, 'i(a,b,c,d,e=3', 5),
|
(code4, 'i(a,b,c,d,e=3', 5),
|
||||||
#(code4, 'i(a,b,c,d=,x=', 3),
|
(code4, 'i(a,b,c,d=,x=', 3),
|
||||||
(code4, 'i(a,b,c,d=5,x=4', 3),
|
(code4, 'i(a,b,c,d=5,x=4', 3),
|
||||||
(code4, 'i(a,b,c,d=5,x=4,y', 4),
|
(code4, 'i(a,b,c,d=5,x=4,y', 4),
|
||||||
(code4, 'i(a,b,c,d=5,x=4,y=3,', 5),
|
(code4, 'i(a,b,c,d=5,x=4,y=3,', 5),
|
||||||
(code4, 'i(a,b,c,d=5,y=4,x=3,', 5),
|
(code4, 'i(a,b,c,d=5,y=4,x=3,', 5),
|
||||||
(code4, 'i(a,b,c,d=4,', 3),
|
(code4, 'i(a,b,c,d=4,', 3),
|
||||||
(code4, 'i(a,b,c,x=1,d=2,', 4),
|
(code4, 'i(a,b,c,x=1,d=,', 4),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_signature_index(skip_pre_python38, Script, code, call, expected_index):
|
def test_signature_index(skip_pre_python38, Script, code, call, expected_index):
|
||||||
|
|||||||
Reference in New Issue
Block a user