Fix diff parser: Invalid dedents meant that sometimes the wrong parents were chosen, fixes davidhalter/jedi#1499

This commit is contained in:
Dave Halter
2020-03-22 12:37:01 +01:00
parent 2cd0d6c9fc
commit 51a044cc70
2 changed files with 38 additions and 3 deletions

View File

@@ -281,10 +281,19 @@ class DiffParser(object):
else:
p_children = line_stmt.parent.children
index = p_children.index(line_stmt)
p_children = p_children[index:]
# There might be a random dedent where we have to stop copying.
# Invalid indents are ok, because the parser handled that
# properly before. An invalid dedent can happen, because a few
# lines above there was an invalid indent.
indentation = line_stmt.start_pos[1]
for i, c in enumerate(p_children):
if c.start_pos[1] < indentation:
p_children = p_children[:i]
from_ = self._nodes_tree.parsed_until_line + 1
copied_nodes = self._nodes_tree.copy_nodes(
p_children[index:],
p_children,
until_line_old,
line_offset
)