forked from VimPlug/jedi
Fix issues with flows in the fast parser.
This commit is contained in:
@@ -174,15 +174,13 @@ class ParserNode(object):
|
|||||||
nodes should be added anymore.
|
nodes should be added anymore.
|
||||||
"""
|
"""
|
||||||
print('CLOSE NODE', id(self), self.parent, self._node_children)
|
print('CLOSE NODE', id(self), self.parent, self._node_children)
|
||||||
if self.parser: print(self.parser.module.names_dict, [p.parser.module.names_dict for p in
|
print(self.parser.module.names_dict, [p.parser.module.names_dict for p in
|
||||||
self._node_children])
|
self._node_children])
|
||||||
# We only need to replace the dict if multiple dictionaries are used:
|
# We only need to replace the dict if multiple dictionaries are used:
|
||||||
if self._node_children:
|
if self._node_children:
|
||||||
dcts = [n.parser.module.names_dict for n in self._node_children]
|
dcts = [n.parser.module.names_dict for n in self._node_children]
|
||||||
if self.parser is not None:
|
# Need to insert the own node as well.
|
||||||
# The first Parser node contains all the others and is
|
dcts.insert(0, self._content_scope.names_dict)
|
||||||
# typically empty.
|
|
||||||
dcts.insert(0, self._content_scope.names_dict)
|
|
||||||
print('DCTS', self.parser, dcts, self._node_children)
|
print('DCTS', self.parser, dcts, self._node_children)
|
||||||
self._content_scope.names_dict = MergedNamesDict(dcts)
|
self._content_scope.names_dict = MergedNamesDict(dcts)
|
||||||
|
|
||||||
@@ -512,6 +510,7 @@ class FastTokenizer(object):
|
|||||||
self._indent_counter = 0
|
self._indent_counter = 0
|
||||||
self._flow_indent_counter = 0
|
self._flow_indent_counter = 0
|
||||||
self._returned_endmarker = False
|
self._returned_endmarker = False
|
||||||
|
self._next_dedent_noclose = False
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
@@ -541,14 +540,19 @@ class FastTokenizer(object):
|
|||||||
self._indent_counter += 1
|
self._indent_counter += 1
|
||||||
elif typ == DEDENT:
|
elif typ == DEDENT:
|
||||||
self._indent_counter -= 1
|
self._indent_counter -= 1
|
||||||
|
print(self._flow_indent_counter)
|
||||||
if self._in_flow and self._indent_counter == self._flow_indent_counter:
|
if self._in_flow and self._indent_counter == self._flow_indent_counter:
|
||||||
self._in_flow = False
|
self._in_flow = False
|
||||||
|
self._next_dedent_noclose = True
|
||||||
return current
|
return current
|
||||||
|
|
||||||
if self.previous[0] == DEDENT and self._indent_counter == 0:
|
if self.previous[0] in (NEWLINE, INDENT, DEDENT):
|
||||||
self._first_stmt = False
|
if self.previous[0] == DEDENT:
|
||||||
return self._close()
|
if not self._next_dedent_noclose:
|
||||||
elif self.previous[0] in (NEWLINE, INDENT):
|
self._first_stmt = False
|
||||||
|
return self._close()
|
||||||
|
if not self._in_flow:
|
||||||
|
self._next_dedent_noclose = False
|
||||||
# Check for NEWLINE, which symbolizes the indent.
|
# Check for NEWLINE, which symbolizes the indent.
|
||||||
#print('X', repr(value), tokenize.tok_name[typ])
|
#print('X', repr(value), tokenize.tok_name[typ])
|
||||||
indent = start_pos[1]
|
indent = start_pos[1]
|
||||||
|
|||||||
@@ -106,8 +106,6 @@ def test_positions():
|
|||||||
|
|
||||||
|
|
||||||
def test_if():
|
def test_if():
|
||||||
# Empty the parser cache for the path None.
|
|
||||||
cache.parser_cache.pop(None, None)
|
|
||||||
src = dedent('''\
|
src = dedent('''\
|
||||||
def func():
|
def func():
|
||||||
x = 3
|
x = 3
|
||||||
@@ -124,6 +122,15 @@ def test_if():
|
|||||||
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
|
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
|
||||||
|
|
||||||
|
|
||||||
|
def test_if_simple():
|
||||||
|
src = dedent('''\
|
||||||
|
if 1:
|
||||||
|
a = 3
|
||||||
|
''')
|
||||||
|
check_fp(src + 'a', 1)
|
||||||
|
check_fp(src + "else:\n a = ''\na", 1)
|
||||||
|
|
||||||
|
|
||||||
def test_incomplete_function():
|
def test_incomplete_function():
|
||||||
source = '''return ImportErr'''
|
source = '''return ImportErr'''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user