1
0
forked from VimPlug/jedi

Fix an issue in the parse call.

This commit is contained in:
Dave Halter
2017-03-26 01:26:01 +01:00
parent 7874026ee5
commit fb8ffde32e
2 changed files with 8 additions and 7 deletions

View File

@@ -100,6 +100,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
kwargs = dict(start_symbol=start_symbol) kwargs = dict(start_symbol=start_symbol)
parser = Parser parser = Parser
# TODO add recovery # TODO add recovery
p = None
if diff_cache: if diff_cache:
try: try:
parser_cache_item = utils.parser_cache[path] parser_cache_item = utils.parser_cache[path]
@@ -111,12 +112,16 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
new_node = DiffParser(p).update(lines) new_node = DiffParser(p).update(lines)
p._parsed = new_node p._parsed = new_node
utils.save_parser(grammar, path, p, pickling=False) utils.save_parser(grammar, path, p, pickling=False)
if added_newline:
p.source = code[:-1]
_remove_last_newline(new_node)
return new_node return new_node
p = parser(grammar, code, start_parsing=False, **kwargs) p = parser(grammar, code, start_parsing=False, **kwargs)
module = p.parse(tokens=tokens) new_node = p.parse(tokens=tokens)
if added_newline: if added_newline:
_remove_last_newline(module) p.source = code[:-1]
_remove_last_newline(new_node)
if use_cache or diff_cache: if use_cache or diff_cache:
utils.save_parser(grammar, path, p) utils.save_parser(grammar, path, p)
return module return new_node

View File

@@ -206,10 +206,6 @@ class DiffParser(object):
debug.speed('diff parser calculated') debug.speed('diff parser calculated')
debug.dbg('diff: line_lengths old: %s, new: %s' % (len(lines_old), line_length)) debug.dbg('diff: line_lengths old: %s, new: %s' % (len(lines_old), line_length))
if len(opcodes) == 1 and opcodes[0][0] == 'equal':
self._copy_count = 1
return self._module
for operation, i1, i2, j1, j2 in opcodes: for operation, i1, i2, j1, j2 in opcodes:
debug.dbg('diff %s old[%s:%s] new[%s:%s]', debug.dbg('diff %s old[%s:%s] new[%s:%s]',
operation, i1 + 1, i2, j1 + 1, j2) operation, i1 + 1, i2, j1 + 1, j2)