forked from VimPlug/jedi
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):
|
if re.search('^\.|\.\.$', path):
|
||||||
return []
|
return []
|
||||||
path, dot, like = self._get_completion_parts(path)
|
path, dot, like = self._get_completion_parts(path)
|
||||||
|
completion_line = self._module.get_line(self.pos[0])[:self.pos[1]]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
scopes = list(self._prepare_goto(path, True))
|
scopes = list(self._prepare_goto(path, True))
|
||||||
@@ -121,8 +122,7 @@ class Script(object):
|
|||||||
else:
|
else:
|
||||||
if isinstance(s, imports.ImportPath):
|
if isinstance(s, imports.ImportPath):
|
||||||
if like == 'import':
|
if like == 'import':
|
||||||
l = self._module.get_line(self.pos[0])[:self.pos[1]]
|
if not completion_line.endswith('import import'):
|
||||||
if not l.endswith('import import'):
|
|
||||||
continue
|
continue
|
||||||
a = s.import_stmt.alias
|
a = s.import_stmt.alias
|
||||||
if a and a.start_pos <= self.pos <= a.end_pos:
|
if a and a.start_pos <= self.pos <= a.end_pos:
|
||||||
@@ -142,10 +142,17 @@ class Script(object):
|
|||||||
completions.append((p.get_name(), p))
|
completions.append((p.get_name(), p))
|
||||||
|
|
||||||
# Do the completion if there is no path before and no import stmt.
|
# Do the completion if there is no path before and no import stmt.
|
||||||
if (not scopes or not isinstance(scopes[0], imports.ImportPath)) \
|
u = self._parser.user_stmt
|
||||||
and not path:
|
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
|
# add keywords
|
||||||
bs = builtin.Builtin.scope
|
|
||||||
completions += ((k, bs) for k in keywords.get_keywords(
|
completions += ((k, bs) for k in keywords.get_keywords(
|
||||||
all=True))
|
all=True))
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class TestRegression(TestBase):
|
|||||||
assert len(self.complete("import import", path='')) > 0
|
assert len(self.complete("import import", path='')) > 0
|
||||||
|
|
||||||
# 111
|
# 111
|
||||||
assert self.complete("from datetime import") == []
|
assert self.complete("from datetime import")[0].word == 'import'
|
||||||
assert self.complete("from datetime import ")
|
assert self.complete("from datetime import ")
|
||||||
|
|
||||||
def test_get_in_function_call(self):
|
def test_get_in_function_call(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user