From 105bb2b1ca9d76d377ed24a10bc7ff0c05a219f3 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 24 May 2013 19:43:23 +0200 Subject: [PATCH 1/4] ModuleWithCursor.get_path_until_cursor cannot handle "\" It raises: IndexError: string index out of range --- test/test_regression.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_regression.py b/test/test_regression.py index e44afb8d..1e72cadf 100755 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -395,6 +395,22 @@ class TestRegression(TestBase): for c in s.get_commands(): self.assertEqual(c.execution.end_pos[1], i) + def test_backslash_continuation(self): + """ + Test that ModuleWithCursor.get_path_until_cursor handles continuation + """ + source = textwrap.dedent(r""" + x = 0 + a = \ + [1, 2, 3, 4, 5, 6, 7, 8, 9, x] # <-- here + """) + for (i, line) in enumerate(source.splitlines()): + if '<-- here' in line: + break + column = len(line) - len('] # <-- here') + defs = self.goto_definitions(source, (i + 1, column)) + self.assertEqual([d.name for d in defs], ['int']) + class TestDocstring(TestBase): From 05564c23d58e2c595604b5f48450d8986b5ecb92 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 24 May 2013 21:06:48 +0200 Subject: [PATCH 2/4] Fix the error --- jedi/modules.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jedi/modules.py b/jedi/modules.py index 37e5bbac..46195c80 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -141,6 +141,7 @@ class ModuleWithCursor(Module): last_line = self.get_line(self._line_temp) if last_line and last_line[-1] == '\\': line = last_line[:-1] + ' ' + line + self._line_length = len(last_line) else: break return line[::-1] From 71455f6b31ac36bbf276852a5a1b84adad133ce9 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 24 May 2013 22:05:12 +0200 Subject: [PATCH 3/4] Add another failing case --- test/test_regression.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/test_regression.py b/test/test_regression.py index 1e72cadf..3753d0bf 100755 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -395,21 +395,42 @@ class TestRegression(TestBase): for c in s.get_commands(): self.assertEqual(c.execution.end_pos[1], i) + def check_definition_by_marker(self, source, after_cursor, names): + r""" + Find definitions specified by `after_cursor` and check what found + + For example, for the following configuration, you can pass + ``after_cursor = 'y)'``.:: + + function( + x, y) + \ + `- You want cursor to be here + """ + source = textwrap.dedent(source) + for (i, line) in enumerate(source.splitlines()): + if after_cursor in line: + break + column = len(line) - len(after_cursor) + defs = self.goto_definitions(source, (i + 1, column)) + self.assertEqual([d.name for d in defs], names) + def test_backslash_continuation(self): """ Test that ModuleWithCursor.get_path_until_cursor handles continuation """ - source = textwrap.dedent(r""" + self.check_definition_by_marker(r""" x = 0 a = \ [1, 2, 3, 4, 5, 6, 7, 8, 9, x] # <-- here - """) - for (i, line) in enumerate(source.splitlines()): - if '<-- here' in line: - break - column = len(line) - len('] # <-- here') - defs = self.goto_definitions(source, (i + 1, column)) - self.assertEqual([d.name for d in defs], ['int']) + """, '] # <-- here', ['int']) + + def test_backslash_continuation_and_bracket(self): + self.check_definition_by_marker(r""" + x = 0 + a = \ + [1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here + """, '(x)] # <-- here', [None]) class TestDocstring(TestBase): From 1f3c4700c9c581bf3f64cf570989788636f259d6 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 24 May 2013 22:09:24 +0200 Subject: [PATCH 4/4] Fix get_path_until_cursor for empty path + continuation --- jedi/modules.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jedi/modules.py b/jedi/modules.py index 46195c80..c583ec5f 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -188,6 +188,7 @@ class ModuleWithCursor(Module): elif token_type == tokenize.NUMBER: pass else: + self._column_temp = self._line_length - end[1] break self._column_temp = self._line_length - end[1]