1
0
forked from VimPlug/jedi

By trying to get rid of search_name in usages, we had to fix an issue with imports:

If used like 'follow(is_goto)', it could return a ModuleWrapper instead of a Name, which is what we actually want.
This commit is contained in:
Dave Halter
2014-09-03 19:30:00 +02:00
parent 59578966cf
commit 18204c4c19
5 changed files with 25 additions and 13 deletions

View File

@@ -502,17 +502,24 @@ class Script(object):
try:
user_stmt = self._parser.user_stmt()
definitions, search_name = self._goto(add_import_name=True)
if not definitions:
# Without a definition for a name we cannot find references.
return []
# Once Script._goto works correct, we can probably remove this
# branch.
if isinstance(user_stmt, pr.Statement):
c = user_stmt.expression_list()[0]
if not isinstance(c, unicode) and self._pos < c.start_pos:
# the search_name might be before `=`
# The lookup might be before `=`
definitions = [v for v in user_stmt.get_defined_names()
if unicode(v.names[-1]) == search_name]
if unicode(v.names[-1]) ==
list(definitions)[0].get_code()]
if not isinstance(user_stmt, pr.Import):
# import case is looked at with add_import_name option
definitions = usages.usages_add_import_modules(self._evaluator,
definitions,
search_name)
definitions)
module = set([d.get_parent_until() for d in definitions])
module.add(self._parser.module())

View File

@@ -46,16 +46,14 @@ def usages(evaluator, definitions, search_name, mods):
#follow_res = [r for r in follow_res if str(r) == search]
#print search.start_pos,search_name.start_pos
#print follow_res, search, search_name, [(r, r.start_pos) for r in follow_res]
follow_res = usages_add_import_modules(evaluator, follow_res, search)
follow_res = usages_add_import_modules(evaluator, follow_res)
compare_follow_res = compare_array(follow_res)
# compare to see if they match
if any(r in compare_definitions for r in compare_follow_res):
yield classes.Definition(evaluator, search)
if not definitions:
return set()
search_name = unicode(list(definitions)[0].names[-1])
compare_definitions = compare_array(definitions)
mods |= set([d.get_parent_until() for d in definitions])
names = []
@@ -86,7 +84,7 @@ def usages(evaluator, definitions, search_name, mods):
return names
def usages_add_import_modules(evaluator, definitions, search_name):
def usages_add_import_modules(evaluator, definitions):
""" Adds the modules of the imports """
new = set()
for d in definitions: