mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Fix an issue with nested flows in the diff parser.
This commit is contained in:
@@ -11,7 +11,7 @@ from jedi._compatibility import use_metaclass
|
|||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.common import splitlines
|
from jedi.common import splitlines
|
||||||
from jedi.parser import ParserWithRecovery
|
from jedi.parser import ParserWithRecovery
|
||||||
from jedi.parser.tree import Module, search_ancestor, EndMarker
|
from jedi.parser.tree import Module, search_ancestor, EndMarker, Flow
|
||||||
from jedi.parser.utils import parser_cache
|
from jedi.parser.utils import parser_cache
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.parser.tokenize import (generate_tokens, NEWLINE, TokenInfo,
|
from jedi.parser.tokenize import (generate_tokens, NEWLINE, TokenInfo,
|
||||||
@@ -360,6 +360,11 @@ class DiffParser(object):
|
|||||||
if parent == nodes[0].get_parent_scope():
|
if parent == nodes[0].get_parent_scope():
|
||||||
check_nodes = nodes
|
check_nodes = nodes
|
||||||
else:
|
else:
|
||||||
|
n = parent
|
||||||
|
while n is not None:
|
||||||
|
if isinstance(n, Flow):
|
||||||
|
parent = n.get_parent_scope()
|
||||||
|
n = n.parent
|
||||||
check_nodes = parent.children
|
check_nodes = parent.children
|
||||||
|
|
||||||
last_node = check_nodes[-1]
|
last_node = check_nodes[-1]
|
||||||
@@ -386,7 +391,6 @@ class DiffParser(object):
|
|||||||
if n.last_leaf().type == 'newline':
|
if n.last_leaf().type == 'newline':
|
||||||
break
|
break
|
||||||
elif _is_flow_node(last_node):
|
elif _is_flow_node(last_node):
|
||||||
# TODO the flows might be part of lower scopes... XXX
|
|
||||||
# If we just copy flows at the end, they might be continued
|
# If we just copy flows at the end, they might be continued
|
||||||
# after the copy limit (in the new parser).
|
# after the copy limit (in the new parser).
|
||||||
drop_node_count += 1
|
drop_node_count += 1
|
||||||
|
|||||||
@@ -318,3 +318,15 @@ def test_unfinished_nodes(differ):
|
|||||||
''')
|
''')
|
||||||
differ.initialize(code)
|
differ.initialize(code)
|
||||||
differ.parse(code2, parsers=1, copies=2)
|
differ.parse(code2, parsers=1, copies=2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_nested_if_and_scopes(differ):
|
||||||
|
code = dedent('''
|
||||||
|
class a():
|
||||||
|
if 1:
|
||||||
|
def b():
|
||||||
|
2
|
||||||
|
''')
|
||||||
|
code2 = code + ' else:\n 3'
|
||||||
|
differ.initialize(code)
|
||||||
|
differ.parse(code2, parsers=1, copies=0)
|
||||||
|
|||||||
Reference in New Issue
Block a user