1
0
forked from VimPlug/jedi

Another endless while loop issue, add an assert.

This commit is contained in:
Dave Halter
2017-03-11 14:54:44 +01:00
parent 818fb4f60c
commit 6e3b00802c
2 changed files with 44 additions and 4 deletions

View File

@@ -194,7 +194,7 @@ class DiffParser(object):
# Good for debugging. # Good for debugging.
if debug.debug_function: if debug.debug_function:
self._enable_debugging(lines_old, lines_new) self._enabled_debugging(lines_old, lines_new)
last_pos = self._module.end_pos[0] last_pos = self._module.end_pos[0]
if last_pos != line_length: if last_pos != line_length:
current_lines = splitlines(self._module.get_code(), keepends=True) current_lines = splitlines(self._module.get_code(), keepends=True)
@@ -207,14 +207,15 @@ class DiffParser(object):
debug.speed('diff parser end') debug.speed('diff parser end')
return self._module return self._module
def _enable_debugging(self, lines_old, lines_new): def _enabled_debugging(self, lines_old, lines_new):
if self._module.get_code() != ''.join(lines_new): if self._module.get_code() != ''.join(lines_new):
debug.warning('parser issue:\n%s\n%s', repr(''.join(lines_old)), debug.warning('parser issue:\n%s\n%s', ''.join(lines_old),
repr(''.join(lines_new))) ''.join(lines_new))
def _copy_from_old_parser(self, line_offset, until_line_old, until_line_new): def _copy_from_old_parser(self, line_offset, until_line_old, until_line_new):
copied_nodes = [None] copied_nodes = [None]
last_until_line = -1
while until_line_new > self._nodes_stack.parsed_until_line: while until_line_new > self._nodes_stack.parsed_until_line:
parsed_until_line_old = self._nodes_stack.parsed_until_line - line_offset parsed_until_line_old = self._nodes_stack.parsed_until_line - line_offset
line_stmt = self._get_old_line_stmt(parsed_until_line_old + 1) line_stmt = self._get_old_line_stmt(parsed_until_line_old + 1)
@@ -247,6 +248,11 @@ class DiffParser(object):
self._copied_ranges.append((from_, to)) self._copied_ranges.append((from_, to))
debug.dbg('diff actually copy %s to %s', from_, to) debug.dbg('diff actually copy %s to %s', from_, to)
# Since there are potential bugs that might loop here endlessly, we
# just stop here.
assert last_until_line != self._nodes_stack.parsed_until_line \
or not copied_nodes, last_until_line
last_until_line = self._nodes_stack.parsed_until_line
def _get_old_line_stmt(self, old_line): def _get_old_line_stmt(self, old_line):
leaf = self._module.get_leaf_for_position((old_line, 0), include_prefixes=True) leaf = self._module.get_leaf_for_position((old_line, 0), include_prefixes=True)

View File

@@ -463,3 +463,37 @@ def test_in_class_movements(differ):
differ.initialize(code1) differ.initialize(code1)
differ.parse(code2, parsers=2, copies=1) differ.parse(code2, parsers=2, copies=1)
def test_in_parentheses_newlines(differ):
code1 = dedent("""
x = str(
True)
a = 1
def foo():
pass
b = 2""")
code2 = dedent("""
x = str(True)
a = 1
def foo():
pass
b = 2""")
script = jedi.Script(code1, line=2, column=8)
assert script.call_signatures()
script = jedi.Script(code2, line=2, column=9)
assert script.call_signatures()
script = jedi.Script(code1, line=2, column=8)
assert script.call_signatures()
differ.initialize(code1)
differ.parse(code2, parsers=1, copies=1)
differ.parse(code1, parsers=1, copies=1)