mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
end_pos issues, fixes #150
This commit is contained in:
@@ -64,6 +64,7 @@ class PushBackIterator(object):
|
|||||||
def __init__(self, iterator):
|
def __init__(self, iterator):
|
||||||
self.pushes = []
|
self.pushes = []
|
||||||
self.iterator = iterator
|
self.iterator = iterator
|
||||||
|
self.current = None
|
||||||
|
|
||||||
def push_back(self, value):
|
def push_back(self, value):
|
||||||
self.pushes.append(value)
|
self.pushes.append(value)
|
||||||
@@ -77,9 +78,10 @@ class PushBackIterator(object):
|
|||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
if self.pushes:
|
if self.pushes:
|
||||||
return self.pushes.pop()
|
self.current = self.pushes.pop()
|
||||||
else:
|
else:
|
||||||
return next(self.iterator)
|
self.current = next(self.iterator)
|
||||||
|
return self.current
|
||||||
|
|
||||||
|
|
||||||
class NoErrorTokenizer(object):
|
class NoErrorTokenizer(object):
|
||||||
|
|||||||
@@ -884,12 +884,9 @@ class Statement(Simple):
|
|||||||
# always dictionaries and not sets.
|
# always dictionaries and not sets.
|
||||||
arr.type = Array.DICT
|
arr.type = Array.DICT
|
||||||
|
|
||||||
k, v = arr.keys, arr.values
|
c = token_iterator.current[1]
|
||||||
latest = (v[-1] if v else k[-1] if k else None)
|
arr.end_pos = c.end_pos if isinstance(c, Simple) \
|
||||||
end_pos = latest.end_pos if latest is not None \
|
else (c[2][0], c[2][1] + len(c[1]))
|
||||||
else (start_pos[0], start_pos[1] + 1)
|
|
||||||
arr.end_pos = end_pos[0], end_pos[1] + (len(break_tok) if break_tok
|
|
||||||
else 0)
|
|
||||||
return arr, break_tok
|
return arr, break_tok
|
||||||
|
|
||||||
def parse_stmt(token_iterator, maybe_dict=False, added_breaks=(),
|
def parse_stmt(token_iterator, maybe_dict=False, added_breaks=(),
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from .base import TestBase, unittest, cwd_at
|
|||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi._compatibility import utf8, unicode
|
from jedi._compatibility import utf8, unicode
|
||||||
from jedi import api
|
from jedi import api, parsing
|
||||||
api_classes = api.api_classes
|
api_classes = api.api_classes
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -378,6 +378,14 @@ class TestRegression(TestBase):
|
|||||||
self.assertEqual([d.description for d in defs],
|
self.assertEqual([d.description for d in defs],
|
||||||
['def f', 'class C'])
|
['def f', 'class C'])
|
||||||
|
|
||||||
|
def test_end_pos(self):
|
||||||
|
# jedi issue #150
|
||||||
|
s = "x()\nx( )\nx( )\nx ( )"
|
||||||
|
parser = parsing.Parser(s)
|
||||||
|
for i, s in enumerate(parser.scope.statements, 3):
|
||||||
|
for c in s.get_commands():
|
||||||
|
self.assertEqual(c.execution.end_pos[1], i)
|
||||||
|
|
||||||
|
|
||||||
class TestDocstring(TestBase):
|
class TestDocstring(TestBase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user