basics/tests for following imports if possible (on completion), #54.

This commit is contained in:
David Halter
2012-12-03 00:56:27 +01:00
parent 1940fbe4fe
commit c28d3617b7
2 changed files with 21 additions and 2 deletions

View File

@@ -91,6 +91,15 @@ class Script(object):
:return: list of Completion objects, sorted by name and __ comes last. :return: list of Completion objects, sorted by name and __ comes last.
:rtype: list :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 = self.module.get_path_until_cursor()
path, dot, like = self._get_completion_parts(path) path, dot, like = self._get_completion_parts(path)
@@ -148,9 +157,13 @@ class Script(object):
or n.startswith(like): or n.startswith(like):
if not evaluate.filter_private_variable(s, if not evaluate.filter_private_variable(s,
self.parser.user_stmt, n): 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) comps.append(new)
return sorted(comps, key=lambda x: (x.word.startswith('__'), return sorted(comps, key=lambda x: (x.word.startswith('__'),
x.word.lower())) x.word.lower()))

View File

@@ -227,6 +227,12 @@ class TestRegression(Base):
s = self.complete("import os; os.P_") s = self.complete("import os; os.P_")
assert 'P_NOWAIT' in [i.word for i in s] 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): class TestFeature(Base):
def test_full_name(self): def test_full_name(self):