forked from VimPlug/jedi
follow inexistant imports in the case of goto - fixes #77
This commit is contained in:
18
jedi/api.py
18
jedi/api.py
@@ -257,7 +257,22 @@ class Script(object):
|
|||||||
def _goto(self, add_import_name=False):
|
def _goto(self, add_import_name=False):
|
||||||
"""
|
"""
|
||||||
Used for goto and related_names.
|
Used for goto and related_names.
|
||||||
|
:param add_import_name: TODO add description
|
||||||
"""
|
"""
|
||||||
|
def follow_inexistent_imports(defs):
|
||||||
|
""" Imports can be generated, e.g. following
|
||||||
|
`multiprocessing.dummy` generates an import dummy in the
|
||||||
|
multiprocessing module. The Import doesn't exist -> follow.
|
||||||
|
"""
|
||||||
|
definitions = set(defs)
|
||||||
|
for d in defs:
|
||||||
|
if isinstance(d.parent, parsing.Import) \
|
||||||
|
and d.start_pos == (0, 0):
|
||||||
|
i = imports.ImportPath(d.parent).follow(is_goto=True)
|
||||||
|
definitions.remove(d)
|
||||||
|
definitions |= follow_inexistent_imports(i)
|
||||||
|
return definitions
|
||||||
|
|
||||||
goto_path = self.module.get_path_under_cursor()
|
goto_path = self.module.get_path_under_cursor()
|
||||||
context = self.module.get_context()
|
context = self.module.get_context()
|
||||||
if next(context) in ('class', 'def'):
|
if next(context) in ('class', 'def'):
|
||||||
@@ -279,7 +294,8 @@ class Script(object):
|
|||||||
definitions.append(import_name[0])
|
definitions.append(import_name[0])
|
||||||
else:
|
else:
|
||||||
stmt = self._get_under_cursor_stmt(goto_path)
|
stmt = self._get_under_cursor_stmt(goto_path)
|
||||||
definitions, search_name = evaluate.goto(stmt)
|
defs, search_name = evaluate.goto(stmt)
|
||||||
|
definitions = follow_inexistent_imports(defs)
|
||||||
return definitions, search_name
|
return definitions, search_name
|
||||||
|
|
||||||
def related_names(self, additional_module_paths=[]):
|
def related_names(self, additional_module_paths=[]):
|
||||||
|
|||||||
Reference in New Issue
Block a user