diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index bc1786e2..a13cd4e5 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -426,7 +426,7 @@ class Script(object): and d.start_pos == (0, 0): i = imports.ImportWrapper(self._evaluator, d.parent).follow(is_goto=True) definitions.remove(d) - definitions |= follow_inexistent_imports(i) + definitions |= follow_inexistent_imports(i.names[-1]) return definitions goto_path = self._user_context.get_path_under_cursor() @@ -449,7 +449,7 @@ class Script(object): if next(context) in ('class', 'def'): # The cursor is on a class/function name. user_scope = self._parser.user_scope() - definitions = set([user_scope.name]) + definitions = set([user_scope.name.names[-1]]) elif isinstance(user_stmt, pr.Import): s, name_part = helpers.get_on_import_stmt(self._evaluator, self._user_context, user_stmt) @@ -461,9 +461,9 @@ class Script(object): if add_import_name: import_name = user_stmt.get_defined_names() # imports have only one name - if not user_stmt.star \ - and unicode(name_part) == unicode(import_name[0].names[-1]): - definitions.append(import_name[0]) + np = import_name[0].names[-1] + if not user_stmt.star and unicode(name_part) == unicode(np): + definitions.append(np) else: # The Evaluator.goto function checks for definitions, but since we # use a reverse tokenizer, we have new name_part objects, so we @@ -472,7 +472,7 @@ class Script(object): for name in user_stmt.get_defined_names(): if name.start_pos <= self._pos <= name.end_pos \ and len(name.names) == 1: - return [name] + return [name.names[0]] defs = self._evaluator.goto(stmt, call_path) definitions = follow_inexistent_imports(defs) diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 94f2e14d..983400a1 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -38,7 +38,7 @@ def defined_names(evaluator, scope): include_builtin=False), None) names = pair[1] if pair else [] names = [n for n in names if isinstance(n, pr.Import) or (len(n) == 1)] - return [Definition(evaluator, d) for d in sorted(names, key=lambda s: s.start_pos)] + return [Definition(evaluator, d.names[-1]) for d in sorted(names, key=lambda s: s.start_pos)] class BaseDefinition(object): @@ -653,6 +653,8 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): d = d.var if isinstance(d, (pr.Name, pr.NamePart)): d = d.get_definition() + if isinstance(d, er.InstanceElement): + d = d.var if isinstance(d, compiled.CompiledObject): typ = d.type() @@ -707,6 +709,8 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): Returns True, if defined as a name in a statement, function or class. Returns False, if it's a reference to such a definition. """ + if isinstance(self._definition, compiled.CompiledName): + return True if not isinstance(self._definition, pr.NamePart): # Currently only handle NameParts. Once we have a proper API, this # will be the standard anyway. diff --git a/jedi/api/usages.py b/jedi/api/usages.py index a2dbb682..a0b91493 100644 --- a/jedi/api/usages.py +++ b/jedi/api/usages.py @@ -7,6 +7,9 @@ from jedi.evaluate import helpers def usages(evaluator, definitions, mods): + """ + :param definitions: list of NameParts + """ def compare_array(definitions): """ `definitions` are being compared by module/start_pos, because sometimes the id's of the objects change (e.g. executions). @@ -54,7 +57,7 @@ def usages(evaluator, definitions, mods): if any(r in compare_definitions for r in compare_follow_res): yield classes.Definition(evaluator, search) - search_name = unicode(list(definitions)[0].names[-1]) + search_name = unicode(list(definitions)[0]) compare_definitions = compare_array(definitions) mods |= set([d.get_parent_until() for d in definitions]) names = []