forked from VimPlug/jedi
Better debugging and solving a test with for stmts.
This commit is contained in:
@@ -133,7 +133,9 @@ class DiffParser(object):
|
|||||||
sm = difflib.SequenceMatcher(None, lines_old, lines_new)
|
sm = difflib.SequenceMatcher(None, lines_old, lines_new)
|
||||||
print(len(lines_old), line_length, lines_old, lines_new)
|
print(len(lines_old), line_length, lines_old, lines_new)
|
||||||
for operation, i1, i2, j1, j2 in sm.get_opcodes():
|
for operation, i1, i2, j1, j2 in sm.get_opcodes():
|
||||||
debug.dbg('diff %s old[%s:%s] new[%s:%s]', operation, i1, i2, j1, j2)
|
debug.dbg('diff %s old[%s:%s] new[%s:%s]',
|
||||||
|
operation, i1 + 1, i2, j1 + 1, j2)
|
||||||
|
|
||||||
if j2 == line_length + int(self._added_newline):
|
if j2 == line_length + int(self._added_newline):
|
||||||
# The empty part after the last newline is not relevant.
|
# The empty part after the last newline is not relevant.
|
||||||
j2 -= 1
|
j2 -= 1
|
||||||
@@ -209,14 +211,19 @@ class DiffParser(object):
|
|||||||
if nodes:
|
if nodes:
|
||||||
print('COPY', until_line_new, nodes)
|
print('COPY', until_line_new, nodes)
|
||||||
self._copy_count += 1
|
self._copy_count += 1
|
||||||
|
debug.dbg(
|
||||||
|
'diff actuall copy %s to %s',
|
||||||
|
nodes[0].start_pos[0],
|
||||||
|
nodes[-1].end_pos[0]
|
||||||
|
)
|
||||||
parent = self._insert_nodes(nodes)
|
parent = self._insert_nodes(nodes)
|
||||||
self._update_names_dict(parent, nodes)
|
self._update_names_dict(parent, nodes)
|
||||||
self._update_positions(nodes, line_offset)
|
self._update_positions(nodes, line_offset)
|
||||||
# We have copied as much as possible (but definitely not too
|
# We have copied as much as possible (but definitely not too
|
||||||
# much). Therefore we escape, even if we're not at the end. The
|
# much). Therefore we just parse the rest.
|
||||||
# rest will be parsed.
|
# We might not reach the end, because there's a statement
|
||||||
# Might not reach until the end, because there's a statement
|
|
||||||
# that is not finished.
|
# that is not finished.
|
||||||
|
self._parse(until_line_new)
|
||||||
break
|
break
|
||||||
|
|
||||||
def _get_old_line_stmt(self, old_line):
|
def _get_old_line_stmt(self, old_line):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from textwrap import dedent
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
|
from jedi import debug
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi.common import splitlines
|
from jedi.common import splitlines
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
@@ -56,11 +57,13 @@ class Differ(object):
|
|||||||
self._first_use = True
|
self._first_use = True
|
||||||
|
|
||||||
def initialize(self, source):
|
def initialize(self, source):
|
||||||
|
debug.dbg('differ: initialize', color='YELLOW')
|
||||||
grammar = load_grammar()
|
grammar = load_grammar()
|
||||||
self.parser = ParserWithRecovery(grammar, source)
|
self.parser = ParserWithRecovery(grammar, source)
|
||||||
return self.parser.module
|
return self.parser.module
|
||||||
|
|
||||||
def parse(self, source, copies=0, parsers=0, allow_error_leafs=False):
|
def parse(self, source, copies=0, parsers=0, allow_error_leafs=False):
|
||||||
|
debug.dbg('differ: parse copies=%s parsers=%s', copies, parsers, color='YELLOW')
|
||||||
lines = splitlines(source, keepends=True)
|
lines = splitlines(source, keepends=True)
|
||||||
diff_parser = DiffParser(self.parser)
|
diff_parser = DiffParser(self.parser)
|
||||||
new_module = diff_parser.update(lines)
|
new_module = diff_parser.update(lines)
|
||||||
@@ -182,11 +185,14 @@ def test_for_on_one_line(differ):
|
|||||||
src = dedent("""\
|
src = dedent("""\
|
||||||
def hi():
|
def hi():
|
||||||
for x in foo: pass
|
for x in foo: pass
|
||||||
|
pass
|
||||||
|
|
||||||
def nested():
|
def nested():
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
differ.parse(src, parsers=1, copies=1)
|
# The second parser is for parsing the `def nested()` which is an `equal`
|
||||||
|
# operation in the SequenceMatcher.
|
||||||
|
differ.parse(src, parsers=2, copies=1)
|
||||||
|
|
||||||
|
|
||||||
def test_open_parentheses(differ):
|
def test_open_parentheses(differ):
|
||||||
|
|||||||
Reference in New Issue
Block a user