mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
basics/tests for following imports if possible (on completion), #54.
This commit is contained in:
15
jedi/api.py
15
jedi/api.py
@@ -91,6 +91,15 @@ class Script(object):
|
||||
:return: list of Completion objects, sorted by name and __ comes last.
|
||||
:rtype: list
|
||||
"""
|
||||
def follow_imports_if_possible(name):
|
||||
par = name.parent()
|
||||
if isinstance(par, parsing.Import):
|
||||
new = imports.ImportPath(par).follow()
|
||||
# Only remove the old entry if a new one has been found.
|
||||
if new:
|
||||
return new
|
||||
return [name]
|
||||
|
||||
path = self.module.get_path_until_cursor()
|
||||
path, dot, like = self._get_completion_parts(path)
|
||||
|
||||
@@ -148,9 +157,13 @@ class Script(object):
|
||||
or n.startswith(like):
|
||||
if not evaluate.filter_private_variable(s,
|
||||
self.parser.user_stmt, n):
|
||||
new = api_classes.Completion( c, needs_dot, len(like), s)
|
||||
for f in follow_imports_if_possible(c):
|
||||
print f, f.parent()
|
||||
new = api_classes.Completion(f, needs_dot,
|
||||
len(like), s)
|
||||
comps.append(new)
|
||||
|
||||
|
||||
return sorted(comps, key=lambda x: (x.word.startswith('__'),
|
||||
x.word.lower()))
|
||||
|
||||
|
||||
@@ -227,6 +227,12 @@ class TestRegression(Base):
|
||||
s = self.complete("import os; os.P_")
|
||||
assert 'P_NOWAIT' in [i.word for i in s]
|
||||
|
||||
def test_follow_imports_if_possible(self):
|
||||
""" github issue #45 """
|
||||
s = self.complete("import datetime.timedelta; datetime.timedelta")
|
||||
print s, [r.name.parent() for r in s], [r.type for r in s]
|
||||
assert 'Import' not in [r.type for r in s]
|
||||
|
||||
|
||||
class TestFeature(Base):
|
||||
def test_full_name(self):
|
||||
|
||||
Reference in New Issue
Block a user