forked from VimPlug/jedi
a follow function for the Importer which solves the issues with follow_definitions
This commit is contained in:
@@ -401,17 +401,12 @@ class Completion(BaseDefinition):
|
|||||||
defs = self._evaluator.eval_statement(self._definition)
|
defs = self._evaluator.eval_statement(self._definition)
|
||||||
elif self._definition.isinstance(pr.Import):
|
elif self._definition.isinstance(pr.Import):
|
||||||
if self._definition.alias is None:
|
if self._definition.alias is None:
|
||||||
print('ha', self._definition, repr(self._name))
|
|
||||||
i = imports.ImportPath(self._evaluator, self._definition, True)
|
i = imports.ImportPath(self._evaluator, self._definition, True)
|
||||||
print('h', i.import_path + [unicode(self._name)])
|
|
||||||
defs = imports.Importer(i.import_path + [unicode(self._name)],
|
defs = imports.Importer(i.import_path + [unicode(self._name)],
|
||||||
i._importer.module).follow_file_system()[0]
|
i._importer.module).follow(self._evaluator)
|
||||||
defs = [defs]
|
|
||||||
print(defs)
|
|
||||||
else:
|
else:
|
||||||
defs = imports.strip_imports(self._evaluator, [self._definition])
|
defs = imports.strip_imports(self._evaluator, [self._definition])
|
||||||
else:
|
else:
|
||||||
print('else', self._definition)
|
|
||||||
return [self]
|
return [self]
|
||||||
|
|
||||||
defs = [BaseDefinition(self._evaluator, d, d.start_pos) for d in defs]
|
defs = [BaseDefinition(self._evaluator, d, d.start_pos) for d in defs]
|
||||||
|
|||||||
@@ -267,29 +267,11 @@ class Importer(object):
|
|||||||
return in_path + sys_path.sys_path_with_modifications(self.module)
|
return in_path + sys_path.sys_path_with_modifications(self.module)
|
||||||
|
|
||||||
def follow(self, evaluator):
|
def follow(self, evaluator):
|
||||||
try:
|
scope, rest = self.follow_file_system()
|
||||||
scope, rest = self._importer.follow_file_system()
|
if rest:
|
||||||
except ModuleNotFound:
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
debug.warning('Module not found: %s', self.import_stmt)
|
return evaluator.follow_path(iter(rest), [scope], scope)
|
||||||
return []
|
return [scope]
|
||||||
|
|
||||||
scopes = [scope]
|
|
||||||
scopes += remove_star_imports(self._evaluator, scope)
|
|
||||||
|
|
||||||
# follow the rest of the import (not FS -> classes, functions)
|
|
||||||
if len(rest) > 1 or rest and self.is_like_search:
|
|
||||||
scopes = []
|
|
||||||
if ['os', 'path'] == self.import_path[:2] \
|
|
||||||
and not self._is_relative_import():
|
|
||||||
# This is a huge exception, we follow a nested import
|
|
||||||
# ``os.path``, because it's a very important one in Python
|
|
||||||
# that is being achieved by messing with ``sys.modules`` in
|
|
||||||
# ``os``.
|
|
||||||
scopes = self._evaluator.follow_path(iter(rest), [scope], scope)
|
|
||||||
elif rest:
|
|
||||||
scopes = itertools.chain.from_iterable(
|
|
||||||
self._evaluator.follow_path(iter(rest), [s], s)
|
|
||||||
for s in scopes)
|
|
||||||
|
|
||||||
def follow_file_system(self):
|
def follow_file_system(self):
|
||||||
if self.file_path:
|
if self.file_path:
|
||||||
@@ -382,7 +364,7 @@ class Importer(object):
|
|||||||
current_namespace = follow_str(rel_path, '__init__')
|
current_namespace = follow_str(rel_path, '__init__')
|
||||||
elif current_namespace[2]: # is a package
|
elif current_namespace[2]: # is a package
|
||||||
for n in self.namespace_packages(current_namespace[1],
|
for n in self.namespace_packages(current_namespace[1],
|
||||||
self.import_path[:i]):
|
self.import_path[:i]):
|
||||||
try:
|
try:
|
||||||
current_namespace = follow_str(n, s)
|
current_namespace = follow_str(n, s)
|
||||||
if current_namespace[1]:
|
if current_namespace[1]:
|
||||||
|
|||||||
Reference in New Issue
Block a user