diff --git a/parso/python/diff.py b/parso/python/diff.py index f6c26a0..271512a 100644 --- a/parso/python/diff.py +++ b/parso/python/diff.py @@ -281,19 +281,10 @@ 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, + p_children[index:], until_line_old, line_offset ) @@ -597,6 +588,15 @@ class _NodesTree(object): # issues. return [] + # 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 = tree_nodes[0].start_pos[1] + for i, c in enumerate(tree_nodes): + if c.start_pos[1] < indentation: + tree_nodes = tree_nodes[:i] + self._get_insertion_node(tree_nodes[0]) new_nodes, self._working_stack, self.prefix = self._copy_nodes(