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:

View File

@@ -188,10 +188,12 @@ class CompiledObject(Base):
pass # self.obj maynot have an __iter__ method.
return result
"""
@property
def name(self):
# might not exist sometimes (raises AttributeError)
return self._cls().obj.__name__
"""
def _execute_function(self, evaluator, params):
if self.type() != 'function':

View File

@@ -194,6 +194,10 @@ class ImportWrapper(pr.Base):
if star_imports:
scopes = [StarImportModule(scopes[0], star_imports)]
# goto only accepts Names or NameParts
if is_goto and not rest:
scopes = [s.name for s in scopes]
# follow the rest of the import (not FS -> classes, functions)
if len(rest) > 1 or rest and self.is_like_search:
scopes = []

View File

@@ -455,11 +455,12 @@ class SubModule(Scope, Module):
else:
sep = (re.escape(os.path.sep),) * 2
r = re.search(r'([^%s]*?)(%s__init__)?(\.py|\.so)?$' % sep, self.path)
# remove PEP 3149 names
# Remove PEP 3149 names
string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
# positions are not real therefore choose (0, 0)
names = [(string, (0, 0))]
return Name(self, names, (0, 0), (0, 0), self.use_as_parent)
# Positions are not real, but a module starts at (1, 0)
p = (1, 0)
names = [(string, p)]
return Name(self, names, p, p, self.use_as_parent)
@property
def has_explicit_absolute_import(self):