forked from VimPlug/jedi
Fix newline stuff for empty parsers.
This commit is contained in:
@@ -312,7 +312,6 @@ class Parser(object):
|
|||||||
|
|
||||||
def remove_last_newline(self):
|
def remove_last_newline(self):
|
||||||
endmarker = self.module.children[-1]
|
endmarker = self.module.children[-1]
|
||||||
print('ENDNL', self.module.children, repr(endmarker.prefix))
|
|
||||||
# The newline is either in the endmarker as a prefix or the previous
|
# The newline is either in the endmarker as a prefix or the previous
|
||||||
# leaf as a newline token.
|
# leaf as a newline token.
|
||||||
if endmarker.prefix.endswith('\n'):
|
if endmarker.prefix.endswith('\n'):
|
||||||
@@ -320,7 +319,10 @@ class Parser(object):
|
|||||||
last_line = re.sub('.*\n', '', endmarker.prefix)
|
last_line = re.sub('.*\n', '', endmarker.prefix)
|
||||||
endmarker.start_pos = endmarker.start_pos[0] - 1, len(last_line)
|
endmarker.start_pos = endmarker.start_pos[0] - 1, len(last_line)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
newline = endmarker.get_previous()
|
newline = endmarker.get_previous()
|
||||||
|
except IndexError:
|
||||||
|
return # This means that the parser is empty.
|
||||||
while True:
|
while True:
|
||||||
if newline.value == '':
|
if newline.value == '':
|
||||||
# Must be a DEDENT, just continue.
|
# Must be a DEDENT, just continue.
|
||||||
|
|||||||
@@ -233,9 +233,6 @@ class LeafWithNewLines(Leaf):
|
|||||||
"""
|
"""
|
||||||
end_pos_line, end_pos_col = self.start_pos
|
end_pos_line, end_pos_col = self.start_pos
|
||||||
lines = self.value.split('\n')
|
lines = self.value.split('\n')
|
||||||
if self.value.endswith('\n'):
|
|
||||||
lines = lines[:-1]
|
|
||||||
lines[-1] += '\n'
|
|
||||||
end_pos_line += len(lines) - 1
|
end_pos_line += len(lines) - 1
|
||||||
# Check for multiline token
|
# Check for multiline token
|
||||||
if self.start_pos[0] == end_pos_line:
|
if self.start_pos[0] == end_pos_line:
|
||||||
|
|||||||
@@ -155,3 +155,11 @@ def test_error_correction_with():
|
|||||||
assert len(comps) > 30
|
assert len(comps) > 30
|
||||||
# `open` completions have a closed attribute.
|
# `open` completions have a closed attribute.
|
||||||
assert [1 for c in comps if c.name == 'closed']
|
assert [1 for c in comps if c.name == 'closed']
|
||||||
|
|
||||||
|
|
||||||
|
def test_newline_positions():
|
||||||
|
endmarker = Parser(load_grammar(), 'a\n').module.children[-1]
|
||||||
|
assert endmarker.end_pos == (2, 0)
|
||||||
|
new_line = endmarker.get_previous()
|
||||||
|
assert new_line.start_pos == (1, 1)
|
||||||
|
assert new_line.end_pos == (2, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user