diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 6c3c619b..21d8fd92 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -471,11 +471,10 @@ class Script(object): # The Evaluator.goto function checks for definitions, but since we # use a reverse tokenizer, we have new name_part objects, so we # have to check the user_stmt here for positions. - if False and isinstance(user_stmt, pr.ExprStmt): + if isinstance(user_stmt, pr.ExprStmt) \ + and isinstance(last_name.parent, pr.ExprStmt): for name in user_stmt.get_defined_names(): - if name.start_pos <= self._pos <= name.end_pos \ - and (not isinstance(name.parent, pr.Call) - or name.parent.next is None): + if name.start_pos <= self._pos <= name.end_pos: return [name] defs = self._evaluator.goto(last_name) diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 7683307a..9e46cd90 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -591,7 +591,14 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): # only show module name d = 'module %s' % self.module_name else: - d = d.get_code().replace('\n', '').replace('\r', '') + first_leaf = d.first_leaf() + # Remove the prefix, because that's not what we want for get_code + # here. + old, first_leaf.prefix = first_leaf.prefix, '' + try: + d = d.get_code().replace('\n', '').replace('\r', '') + finally: + first_leaf.prefix = old return d @property diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 6723db11..e1343cdc 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -443,6 +443,10 @@ class Evaluator(object): return self.eval_element(call) def goto(self, name): + stmt = name.parent + if isinstance(stmt, pr.ExprStmt) and name in stmt.get_defined_names(): + return [name] + scope = name.get_parent_scope() if pr.is_node(name.parent, 'trailer'): call = call_of_name(name, cut_own_trailer=True) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 65d456c4..9cbdfe84 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -445,6 +445,13 @@ class Simple(Base): return result return None + def first_leaf(self): + try: + return self.children[0].first_leaf() + except AttributeError: + return self.children[0] + + def __repr__(self): code = self.get_code().replace('\n', ' ') if not is_py3: