mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Try to make parsed trees more similar for incomplete dedents, see also davidhalter/jedi#1499
This commit is contained in:
@@ -507,23 +507,32 @@ class _NodesTree(object):
|
|||||||
def _get_insertion_node(self, indentation_node):
|
def _get_insertion_node(self, indentation_node):
|
||||||
indentation = indentation_node.start_pos[1]
|
indentation = indentation_node.start_pos[1]
|
||||||
|
|
||||||
|
previous_node = None
|
||||||
# find insertion node
|
# find insertion node
|
||||||
while True:
|
for node in reversed(self._working_stack):
|
||||||
node = self._working_stack[-1]
|
|
||||||
tree_node = node.tree_node
|
tree_node = node.tree_node
|
||||||
if tree_node.type == 'suite':
|
if tree_node.type == 'suite':
|
||||||
# A suite starts with NEWLINE, ...
|
# A suite starts with NEWLINE, ...
|
||||||
node_indentation = tree_node.children[1].start_pos[1]
|
node_indentation = tree_node.children[1].start_pos[1]
|
||||||
|
|
||||||
|
if indentation > node_indentation and previous_node is not None:
|
||||||
|
# This means that it was not dedented enough.
|
||||||
|
node = previous_node
|
||||||
|
break
|
||||||
if indentation >= node_indentation: # Not a Dedent
|
if indentation >= node_indentation: # Not a Dedent
|
||||||
# We might be at the most outer layer: modules. We
|
# We might be at the most outer layer: modules. We
|
||||||
# don't want to depend on the first statement
|
# don't want to depend on the first statement
|
||||||
# having the right indentation.
|
# having the right indentation.
|
||||||
return node
|
break
|
||||||
|
|
||||||
elif tree_node.type == 'file_input':
|
elif tree_node.type == 'file_input':
|
||||||
return node
|
if indentation > 0 and previous_node is not None:
|
||||||
|
node = previous_node
|
||||||
|
break
|
||||||
|
previous_node = node
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if node == self._working_stack[-1]:
|
||||||
|
return node
|
||||||
self._working_stack.pop()
|
self._working_stack.pop()
|
||||||
|
|
||||||
def add_parsed_nodes(self, tree_nodes):
|
def add_parsed_nodes(self, tree_nodes):
|
||||||
|
|||||||
Reference in New Issue
Block a user