forked from VimPlug/jedi
the fast parser was able to return wrong sub parsers, because the sometimes hashes were not updated, fixes #396.
This commit is contained in:
@@ -72,14 +72,14 @@ class CachedFastParser(type):
|
|||||||
class ParserNode(object):
|
class ParserNode(object):
|
||||||
def __init__(self, parser, code, parent=None):
|
def __init__(self, parser, code, parent=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.code = code
|
|
||||||
self.hash = hash(code)
|
|
||||||
|
|
||||||
self.children = []
|
self.children = []
|
||||||
# must be created before new things are added to it.
|
# must be created before new things are added to it.
|
||||||
self.save_contents(parser)
|
self.save_contents(parser, code)
|
||||||
|
|
||||||
def save_contents(self, parser):
|
def save_contents(self, parser, code):
|
||||||
|
self.code = code
|
||||||
|
self.hash = hash(code)
|
||||||
self.parser = parser
|
self.parser = parser
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -325,7 +325,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
if self.current_node is None:
|
if self.current_node is None:
|
||||||
self.current_node = ParserNode(new, '')
|
self.current_node = ParserNode(new, '')
|
||||||
else:
|
else:
|
||||||
self.current_node.save_contents(new)
|
self.current_node.save_contents(new, '')
|
||||||
self.parsers.append(new)
|
self.parsers.append(new)
|
||||||
is_first = False
|
is_first = False
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
if self.current_node is None:
|
if self.current_node is None:
|
||||||
self.current_node = ParserNode(p, code_part_actually_used)
|
self.current_node = ParserNode(p, code_part_actually_used)
|
||||||
else:
|
else:
|
||||||
self.current_node.save_contents(p)
|
self.current_node.save_contents(p, code_part_actually_used)
|
||||||
else:
|
else:
|
||||||
if node is None:
|
if node is None:
|
||||||
self.current_node = \
|
self.current_node = \
|
||||||
|
|||||||
@@ -59,18 +59,22 @@ def test_carriage_return_splitting():
|
|||||||
|
|
||||||
|
|
||||||
def test_change_and_undo():
|
def test_change_and_undo():
|
||||||
cache.parser_cache.pop(None, None)
|
|
||||||
|
|
||||||
def fp(src):
|
def fp(src):
|
||||||
p = FastParser(u(src))
|
p = FastParser(u(src))
|
||||||
cache.save_parser(None, None, p, pickling=False)
|
cache.save_parser(None, None, p, pickling=False)
|
||||||
|
|
||||||
# TODO Don't just take the first line, the whole thing should be the same.
|
# TODO Don't change get_code, the whole thing should be the same.
|
||||||
# Need to refactor the parser first, though.
|
# -> Need to refactor the parser first, though.
|
||||||
print(repr(p.module.get_code()))
|
assert src == p.module.get_code()[:-1]
|
||||||
first_line = p.module.get_code().splitlines()[0]
|
|
||||||
assert first_line == src
|
|
||||||
|
|
||||||
|
cache.parser_cache.pop(None, None)
|
||||||
|
func_before = 'def func():\n pass\n'
|
||||||
|
fp(func_before + 'a')
|
||||||
|
fp(func_before + 'b')
|
||||||
|
fp(func_before + 'a')
|
||||||
|
|
||||||
|
cache.parser_cache.pop(None, None)
|
||||||
fp('a')
|
fp('a')
|
||||||
fp('b')
|
fp('b')
|
||||||
fp('a')
|
fp('a')
|
||||||
|
|||||||
Reference in New Issue
Block a user