From 0def3afaaaf6f078a17966815b272bb4a260b9e5 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 12 Oct 2014 23:37:46 +0200 Subject: [PATCH] A move function for Nodes. --- jedi/api/__init__.py | 9 ++++----- jedi/evaluate/imports.py | 1 + jedi/parser/representation.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 1a864356..c5f048da 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -264,7 +264,9 @@ class Script(object): # goto_definition returns definitions of its statements if the # cursor is on the assignee. By changing the start_pos of our # "pseudo" statement, the Jedi evaluator can find the assignees. - if user_stmt is not None: + + # TODO remove? + if False and user_stmt is not None: eval_stmt.start_pos = user_stmt.end_pos scopes = self._evaluator.eval_statement(eval_stmt) @@ -291,10 +293,7 @@ class Script(object): else: pos = user_stmt.start_pos - child = stmt - while hasattr(child, 'children'): - child = child.children[0] - child.start_pos = pos + stmt.move(pos[0] - 1, pos[1]) stmt.parent = self._parser.user_scope() return stmt diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index bd6ca11e..bbf49595 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -39,6 +39,7 @@ class ModuleNotFound(Exception): class ImportWrapper(): + GlobalNamespace = 'TODO PLEASE DELETE ME' def __init__(self, evaluator, name): self._evaluator = evaluator self._name = name diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index fbb07b06..ae040631 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -286,6 +286,17 @@ class Simple(Base): self.children = children self.parent = None + def move(self, line_offset, column_offset): + """ + Move the Node's start_pos. + """ + for c in self.children: + if isinstance(c, _Leaf): + c.start_pos = (c.start_pos[0] + line_offset, + c.start_pos[1] + column_offset) + else: + c.move(line_offset, column_offset) + @property def start_pos(self): return self.children[0].start_pos