mirror of
https://github.com/davidhalter/parso.git
synced 2026-03-01 12:57:14 +08:00
Fix diff parser: Don't copy error nodes/leaves in the beginning, leads to strange issues in some cases
This commit is contained in:
@@ -578,8 +578,14 @@ class _NodesTree(object):
|
||||
|
||||
Returns the number of tree nodes that were copied.
|
||||
"""
|
||||
if tree_nodes[0].type == 'error_leaf' and tree_nodes[0].token_type == 'INDENT':
|
||||
# Avoid copying error indents. Just parse them again.
|
||||
i = 0
|
||||
for i, n in enumerate(tree_nodes):
|
||||
if tree_nodes[0].type not in ('INDENT', 'DEDENT'):
|
||||
break
|
||||
|
||||
if tree_nodes[i].type in ('error_leaf', 'error_node'):
|
||||
# Avoid copying errors in the beginning. Can lead to a lot of
|
||||
# issues.
|
||||
return []
|
||||
|
||||
self._get_insertion_node(tree_nodes[0])
|
||||
@@ -622,10 +628,6 @@ class _NodesTree(object):
|
||||
|
||||
new_nodes.append(node)
|
||||
|
||||
while new_nodes and new_nodes[0].type == 'error_leaf' \
|
||||
and new_nodes[0].token_type in _INDENTATION_TOKENS:
|
||||
new_nodes.pop(0)
|
||||
|
||||
if not new_nodes:
|
||||
return [], working_stack, prefix
|
||||
|
||||
|
||||
Reference in New Issue
Block a user