forked from VimPlug/jedi
Goto should not include imports that cannot be followed.
This commit is contained in:
@@ -429,8 +429,11 @@ class Script(object):
|
||||
user_scope = self._parser.user_scope()
|
||||
definitions = set([user_scope.name])
|
||||
elif isinstance(user_stmt, pr.Import):
|
||||
s, name_part = helpers.get_on_import_stmt(self._evaluator,
|
||||
s, name = helpers.get_on_import_stmt(self._evaluator,
|
||||
self._user_context, user_stmt)
|
||||
|
||||
definitions = self._evaluator.goto(name)
|
||||
"""
|
||||
try:
|
||||
definitions = [s.follow(is_goto=True)[0]]
|
||||
except IndexError:
|
||||
@@ -442,6 +445,7 @@ class Script(object):
|
||||
np = import_name[0]
|
||||
if not user_stmt.is_star_import() 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,6 +476,12 @@ class Script(object):
|
||||
try:
|
||||
user_stmt = self._parser.user_stmt()
|
||||
definitions = self._goto(add_import_name=True)
|
||||
if not definitions and isinstance(user_stmt, pr.Import):
|
||||
# For not defined imports (goto doesn't find something, we take
|
||||
# the name as a definition. This is enough, because every name
|
||||
# points to it.
|
||||
definitions = [user_stmt.name_for_position(self._pos)]
|
||||
|
||||
if not definitions:
|
||||
# Without a definition for a name we cannot find references.
|
||||
return []
|
||||
|
||||
@@ -305,6 +305,7 @@ class Evaluator(object):
|
||||
s = imports.ImportWrapper(self, name)
|
||||
for n in s.follow(is_goto=True):
|
||||
yield n
|
||||
else:
|
||||
yield name
|
||||
|
||||
stmt = name.get_definition()
|
||||
@@ -340,7 +341,8 @@ class Evaluator(object):
|
||||
elif isinstance(par, (pr.Param, pr.Function, pr.Class)) and par.name is name:
|
||||
return [name]
|
||||
elif isinstance(stmt, pr.Import):
|
||||
return imports.ImportWrapper(self, name).follow(is_goto=True)
|
||||
modules = imports.ImportWrapper(self, name).follow(is_goto=True)
|
||||
return list(resolve_implicit_imports(modules))
|
||||
elif par.type == 'dotted_name': # Is a decorator.
|
||||
index = par.children.index(name)
|
||||
if index > 0:
|
||||
|
||||
@@ -104,19 +104,22 @@ class ImportWrapper(pr.Base):
|
||||
|
||||
if from_import_name is not None:
|
||||
types = list(chain.from_iterable(
|
||||
self._evaluator.find_types(s, from_import_name, is_goto)
|
||||
self._evaluator.find_types(s, from_import_name, is_goto=is_goto)
|
||||
for s in types))
|
||||
if not types:
|
||||
importer = get_importer(self._evaluator,
|
||||
tuple(import_path + [from_import_name]),
|
||||
module, self._import.level)
|
||||
types, _ = importer.follow_file_system()
|
||||
|
||||
|
||||
|
||||
# goto only accepts `Name`
|
||||
if is_goto and not rest:
|
||||
if is_goto:
|
||||
types = [s.name for s in types]
|
||||
else:
|
||||
# goto only accepts `Name`
|
||||
if is_goto:
|
||||
types = [s.name for s in types]
|
||||
|
||||
|
||||
|
||||
"""
|
||||
# follow the rest of the import (not FS -> classes, functions)
|
||||
@@ -298,7 +301,7 @@ class _Importer(object):
|
||||
@memoize_default(NO_DEFAULT)
|
||||
def follow_file_system(self):
|
||||
if not self.import_path:
|
||||
return None, []
|
||||
return [], []
|
||||
modules = self._do_import(self.import_path, self.sys_path_with_modifications())
|
||||
return modules, []
|
||||
|
||||
@@ -413,6 +416,8 @@ class _Importer(object):
|
||||
else:
|
||||
debug.dbg('search_module %s in paths %s', module_name, paths)
|
||||
for path in paths:
|
||||
# At the moment we are only using one path. So this is
|
||||
# not important to be correct.
|
||||
module_file, module_path, is_pkg = \
|
||||
find_module(import_parts[-1], [path])
|
||||
else:
|
||||
|
||||
@@ -775,7 +775,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
||||
return name
|
||||
|
||||
def py__file__(self):
|
||||
return self._module.path
|
||||
return os.path.abspath(self._module.path)
|
||||
|
||||
def py__package__(self):
|
||||
if self._get_init_directory() is None:
|
||||
|
||||
@@ -179,7 +179,7 @@ def _get_paths_from_buildout_script(evaluator, buildout_script):
|
||||
cache.save_parser(buildout_script, p)
|
||||
return p.module
|
||||
|
||||
cached = cache.load_parser(buildout_script, None)
|
||||
cached = cache.load_parser(buildout_script)
|
||||
module = cached and cached.module or load(buildout_script)
|
||||
if not module:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user