mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-19 17:43:07 +08:00
Fix diff parser: Invalid dedents meant that sometimes the wrong parents were chosen, fixes davidhalter/jedi#1499
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user