diff --git a/jedi/parser/tokenize.py b/jedi/parser/tokenize.py index 9d2cf9af..359c025b 100644 --- a/jedi/parser/tokenize.py +++ b/jedi/parser/tokenize.py @@ -211,7 +211,8 @@ def generate_tokens(readline, line_offset=0): if column > indents[-1]: # count indents or dedents indents.append(column) - yield TokenInfo(INDENT, line[:pos], (lnum, 0), (lnum, pos)) + #print repr(line), lnum + #yield TokenInfo(INDENT, line[:pos], (lnum, 0), (lnum, pos)) while column < indents[-1]: indents = indents[:-1] diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index 904bf063..e69a3b7f 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -30,11 +30,14 @@ class UserContext(object): return path def _calc_path_until_cursor(self, start_pos=None): + """ + Something like a reverse tokenizer that tokenizes the reversed strings. + """ def fetch_line(): if self._is_first: self._is_first = False self._line_length = self._column_temp - line = self._first_line + line = first_line else: line = self.get_line(self._line_temp) self._line_length = len(line) @@ -53,7 +56,7 @@ class UserContext(object): self._is_first = True self._line_temp, self._column_temp = start_cursor = start_pos - self._first_line = self.get_line(self._line_temp)[:self._column_temp] + first_line = self.get_line(self._line_temp)[:self._column_temp] open_brackets = ['(', '[', '{'] close_brackets = [')', ']', '}'] @@ -63,7 +66,13 @@ class UserContext(object): level = 0 force_point = False last_type = None + is_first = True for token_type, tok, start, end in gen: + if is_first: + if start != (1, 0): # whitespace is not a path + return '', start_cursor + is_first = False + # print 'tok', token_type, tok, force_point if last_type == token_type == tokenize.NAME: string += ' ' @@ -94,7 +103,7 @@ class UserContext(object): x = start_pos[0] - end[0] + 1 l = self.get_line(x) - l = self._first_line if x == start_pos[0] else l + l = first_line if x == start_pos[0] else l start_cursor = x, len(l) - end[1] self._column_temp = self._line_length - end[1] string += tok diff --git a/test/test_integration_import.py b/test/test_integration_import.py index 92f2ec02..4861a733 100644 --- a/test/test_integration_import.py +++ b/test/test_integration_import.py @@ -63,8 +63,8 @@ def test_after_from(): completions = Script(source, column=column).completions() assert [c.name for c in completions] == result - check('from os ', ['import']) check('\nfrom os ', ['import']) + check('from os ', ['import']) check('\nfrom os import whatever', ['import'], len('from os im')) check('from os\\\n', ['import'])