Fix diff parser: Don't copy error nodes/leaves in the beginning, leads to strange issues in some cases

This commit is contained in:
Dave Halter
2019-01-17 23:48:00 +01:00
parent 32321a74b1
commit 197391dc53
2 changed files with 32 additions and 10 deletions

View File

@@ -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