mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
improved import statement keyword autocompletion, #111
This commit is contained in:
17
jedi/api.py
17
jedi/api.py
@@ -101,6 +101,7 @@ class Script(object):
|
||||
if re.search('^\.|\.\.$', path):
|
||||
return []
|
||||
path, dot, like = self._get_completion_parts(path)
|
||||
completion_line = self._module.get_line(self.pos[0])[:self.pos[1]]
|
||||
|
||||
try:
|
||||
scopes = list(self._prepare_goto(path, True))
|
||||
@@ -121,8 +122,7 @@ class Script(object):
|
||||
else:
|
||||
if isinstance(s, imports.ImportPath):
|
||||
if like == 'import':
|
||||
l = self._module.get_line(self.pos[0])[:self.pos[1]]
|
||||
if not l.endswith('import import'):
|
||||
if not completion_line.endswith('import import'):
|
||||
continue
|
||||
a = s.import_stmt.alias
|
||||
if a and a.start_pos <= self.pos <= a.end_pos:
|
||||
@@ -142,10 +142,17 @@ class Script(object):
|
||||
completions.append((p.get_name(), p))
|
||||
|
||||
# Do the completion if there is no path before and no import stmt.
|
||||
if (not scopes or not isinstance(scopes[0], imports.ImportPath)) \
|
||||
and not path:
|
||||
# add keywords
|
||||
u = self._parser.user_stmt
|
||||
bs = builtin.Builtin.scope
|
||||
if isinstance(u, parsing.Import):
|
||||
if (u.relative_count > 0 or u.from_ns) and not re.search(
|
||||
r'(,|from)\s*$|import\s+$', completion_line):
|
||||
completions += ((k, bs) for k
|
||||
in keywords.get_keywords('import'))
|
||||
u = None
|
||||
|
||||
if not path and not isinstance(u, parsing.Import):
|
||||
# add keywords
|
||||
completions += ((k, bs) for k in keywords.get_keywords(
|
||||
all=True))
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class TestRegression(TestBase):
|
||||
assert len(self.complete("import import", path='')) > 0
|
||||
|
||||
# 111
|
||||
assert self.complete("from datetime import") == []
|
||||
assert self.complete("from datetime import")[0].word == 'import'
|
||||
assert self.complete("from datetime import ")
|
||||
|
||||
def test_get_in_function_call(self):
|
||||
|
||||
Reference in New Issue
Block a user