From 1ed94060df0d8788f2bbfd770f4c29b5e63d2dc0 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 28 Jul 2013 21:19:03 +0200 Subject: [PATCH] fix another position problem with the reverse tokenizer. includes tests. --- jedi/modules.py | 16 ++++++++++------ test/test_regression.py | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/jedi/modules.py b/jedi/modules.py index e9c6ae48..a8193bed 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -122,17 +122,17 @@ class ModuleWithCursor(Module): def get_path_until_cursor(self): """ Get the path under the cursor. """ result = self._get_path_until_cursor() - self._start_cursor_pos = self._last_tok_line, self._column_temp + self._start_cursor_pos = self._start_cursor_pos_temp return result def _get_path_until_cursor(self, start_pos=None): def fetch_line(): - line = self.get_line(self._line_temp) if self._is_first: self._is_first = False self._line_length = self._column_temp - line = line[:self._column_temp] + line = self._first_line else: + line = self.get_line(self._line_temp) self._line_length = len(line) line = line + '\n' # add lines with a backslash at the end @@ -149,7 +149,8 @@ class ModuleWithCursor(Module): self._is_first = True self._line_temp, self._column_temp = start_pos or self.position - self._last_tok_line = self.position[0] + self._first_line = self.get_line(self._line_temp)[:self._column_temp] + self._start_cursor_pos_temp = self.position open_brackets = ['(', '[', '{'] close_brackets = [')', ']', '}'] @@ -189,7 +190,10 @@ class ModuleWithCursor(Module): self._column_temp = self._line_length - end[1] break - self._last_tok_line = self.position[0] - end[0] + 1 + x = self.position[0] - end[0] + 1 + l = self.get_line(x) + l = self._first_line if x == self.position[0] else l + self._start_cursor_pos_temp = x, len(l) - end[1] self._column_temp = self._line_length - end[1] string += tok last_type = token_type @@ -236,7 +240,7 @@ class ModuleWithCursor(Module): if not self._line_cache: self._line_cache = self.source.splitlines() if not self.source: # ''.splitlines() == [] - self._line_cache = [self.source] + self._line_cache = [''] if line_nr == 0: # This is a fix for the zeroth line. We need a newline there, for diff --git a/test/test_regression.py b/test/test_regression.py index 1f81ad64..891c552c 100755 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -425,6 +425,10 @@ class TestRegression(TestBase): [1, 2, 3, 4, 5, 6, 7, 8, 9, x] # <-- here """, '] # <-- here', ['int']) + # completion in whitespace + s = 'asdfxyxxxxxxxx sds\\\n hello' + assert self.goto_assignments(s, (2, 4)) == [] + def test_backslash_continuation_and_bracket(self): self.check_definition_by_marker(r""" x = 0