empty import statement completion.

This commit is contained in:
Dave Halter
2014-12-11 15:24:19 +01:00
parent bf8645d615
commit 003d1249c5
4 changed files with 57 additions and 14 deletions
+11 -8
View File
@@ -141,19 +141,22 @@ class Script(object):
i = imports.get_importer(self._evaluator, imp_names, module, level)
c_names = i.completion_names(self._evaluator, only_modules)
completions = [(name, module) for name in c_names]
if isinstance(user_stmt, pr.Import):
# TODO this paragraph is necessary, but not sure it works.
context = self._user_context.get_context()
next(context) # skip the path
# TODO this paragraph is necessary, but not sure it works.
context = self._user_context.get_context()
print(next(self._user_context.get_context()), 'x')
if not next(context).startswith('.'): # skip the path
if next(context) == 'from':
# completion is just "import" if before stands from ..
completions += ((k, bs) for k in keywords.keyword_names('import'))
return completions
if isinstance(user_stmt, pr.Import):
module = self._parser.module()
name = user_stmt.name_for_position(self._pos)
if name is not None:
imp = imports.ImportWrapper(self._evaluator, name)
completions += [(n, module) for n in imp.completion_names()]
completion_names = imports.completion_names(self._evaluator,
user_stmt, self._pos)
return completions + [(n, module) for n in completion_names]
if names is None and not isinstance(user_stmt, pr.Import):
if not path and not dot:
+5 -3
View File
@@ -59,13 +59,15 @@ def importer_from_error_statement(error_statement, pos):
return None, 0, False
elif typ == 'import_from':
for node in nodes:
if isinstance(node, pt.Node) and node.type == 'dotted_name':
if node.start_pos >= pos:
break
elif isinstance(node, pt.Node) and node.type == 'dotted_name':
names += check_dotted(node.children)
elif node in ('.', '...'):
level += len(node.value)
elif isinstance(node, pt.Name) and node.start_pos <= pos:
elif isinstance(node, pt.Name):
names.append(node)
elif node == 'import' and node.start_pos <= pos:
elif node == 'import':
only_modules = False
return names, level, only_modules