1
0
forked from VimPlug/jedi

Fix an issue with end_pos of a module.

This commit is contained in:
Dave Halter
2016-07-08 00:03:52 +02:00
parent c499696b60
commit e5f09e1c7d
3 changed files with 24 additions and 4 deletions

View File

@@ -232,10 +232,19 @@ class Parser(object):
endmarker = self._parsed.children[-1]
# The newline is either in the endmarker as a prefix or the previous
# leaf as a newline token.
if endmarker.prefix.endswith('\n'):
endmarker.prefix = endmarker.prefix[:-1]
last_line = re.sub('.*\n', '', endmarker.prefix)
endmarker._start_pos = endmarker._start_pos[0] - 1, len(last_line)
prefix = endmarker.prefix
if prefix.endswith('\n'):
endmarker.prefix = prefix = prefix[:-1]
last_end = 0
if '\n' not in prefix:
# Basically if the last line doesn't end with a newline. we
# have to add the previous line's end_position.
try:
last_end = endmarker.get_previous_leaf().end_pos[1]
except IndexError:
pass
last_line = re.sub('.*\n', '', prefix)
endmarker._start_pos = endmarker._start_pos[0] - 1, last_end + len(last_line)
else:
try:
newline = endmarker.get_previous_leaf()
@@ -251,6 +260,7 @@ class Parser(object):
# will be no previous leaf. So just ignore it.
break
elif newline.value != '\n':
# TODO REMOVE, error recovery was simplified.
# This may happen if error correction strikes and removes
# a whole statement including '\n'.
break

View File

@@ -369,3 +369,11 @@ def test_different_caller():
assert_signature('(str)(', 'str', 0)
assert_signature('(str)()', 'str', 0, column=len('(str)('))
def test_in_function():
code = dedent('''\
class X():
@property
def func(''')
assert not Script(code).call_signatures()

View File

@@ -103,3 +103,5 @@ def test_end_newlines():
test('a\n#comment', (2, 8))
test('a#comment', (1, 9))
test('def a():\n pass', (2, 5))
test('def a(', (1, 6))