mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
get_definition on import statements talked about in issue #7
This commit is contained in:
12
evaluate.py
12
evaluate.py
@@ -1443,11 +1443,15 @@ def goto(scopes, search_name=None, statement_path_offset=1):
|
|||||||
definitions = []
|
definitions = []
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
if isinstance(s, imports.ImportPath):
|
if isinstance(s, imports.ImportPath):
|
||||||
s = s.follow()[0]
|
|
||||||
try:
|
try:
|
||||||
s = statement_path[0]
|
s = s.follow()[0]
|
||||||
except IndexError:
|
except imports.ModuleNotFound:
|
||||||
pass
|
continue
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
s = statement_path[0]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
definitions.append(s)
|
definitions.append(s)
|
||||||
else:
|
else:
|
||||||
def remove_unreal_imports(names):
|
def remove_unreal_imports(names):
|
||||||
|
|||||||
@@ -233,6 +233,12 @@ def get_definition(source, line, column, source_path):
|
|||||||
else:
|
else:
|
||||||
scopes = set(_prepare_goto(source, pos, source_path, f, goto_path))
|
scopes = set(_prepare_goto(source, pos, source_path, f, goto_path))
|
||||||
|
|
||||||
|
for s in scopes.copy():
|
||||||
|
if isinstance(s, imports.ImportPath):
|
||||||
|
scopes.remove(s)
|
||||||
|
evaluate.statement_path = []
|
||||||
|
scopes.update(evaluate.goto([s]))
|
||||||
|
|
||||||
# add keywords
|
# add keywords
|
||||||
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,10 @@ class TestRegression(unittest.TestCase):
|
|||||||
s = self.complete("", (1,0))
|
s = self.complete("", (1,0))
|
||||||
assert len(s) > 0
|
assert len(s) > 0
|
||||||
|
|
||||||
|
def test_get_definition_on_import(self):
|
||||||
|
assert self.get_def("import os_blabla", (1, 8)) == []
|
||||||
|
assert len(self.get_def("import os", (1, 8))) == 1
|
||||||
|
|
||||||
def test_new(self):
|
def test_new(self):
|
||||||
""" This is just to try out things, removing or deleting it is ok. """
|
""" This is just to try out things, removing or deleting it is ok. """
|
||||||
s = ("def abc(): pass\n"
|
s = ("def abc(): pass\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user