forked from VimPlug/jedi
First implementation to be ready to complete corrupt imports. Working ok.
This commit is contained in:
@@ -129,6 +129,14 @@ class Script(object):
|
||||
:rtype: list of :class:`classes.Completion`
|
||||
"""
|
||||
def get_completions(user_stmt, bs):
|
||||
if user_stmt is None:
|
||||
module = self._parser.module()
|
||||
importer = helpers.check_error_statements(
|
||||
self._evaluator, module, self._pos
|
||||
)
|
||||
print(importer.completion_names(self._evaluator, True))
|
||||
return [(name, module) for name in importer.completion_names(self._evaluator, True)]
|
||||
# TODO DELETE still needed?
|
||||
if isinstance(user_stmt, pr.Import):
|
||||
context = self._user_context.get_context()
|
||||
next(context) # skip the path
|
||||
@@ -155,6 +163,7 @@ class Script(object):
|
||||
path, dot, like = helpers.completion_parts(path)
|
||||
|
||||
user_stmt = self._parser.user_stmt_with_whitespace()
|
||||
|
||||
b = compiled.builtin
|
||||
completions = get_completions(user_stmt, b)
|
||||
|
||||
|
||||
@@ -31,3 +31,21 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
|
||||
|
||||
i = imports.ImportWrapper(evaluator, name)
|
||||
return i, name
|
||||
|
||||
|
||||
def check_error_statements(evaluator, module, pos):
|
||||
for error_statement in module.error_statement_stacks:
|
||||
if error_statement.first_type in ('import_from' or 'import_name') \
|
||||
and error_statement.first_pos < pos <= error_statement.next_start_pos:
|
||||
return importer_from_error_statement(evaluator, module, error_statement, pos)
|
||||
return None
|
||||
|
||||
|
||||
def importer_from_error_statement(evaluator, module, error_statement, pos):
|
||||
names = []
|
||||
level = 0
|
||||
for typ, nodes in error_statement.stack:
|
||||
if typ == 'dotted_name':
|
||||
names += nodes[::2]
|
||||
|
||||
return imports.get_importer(evaluator, names, module, level)
|
||||
|
||||
Reference in New Issue
Block a user