1
0
forked from VimPlug/jedi

Last few on_import fixes.

This commit is contained in:
Dave Halter
2014-12-08 14:15:21 +01:00
parent 6cc4d71822
commit 034d782e65
4 changed files with 26 additions and 33 deletions

View File

@@ -144,14 +144,15 @@ class Script(object):
# TODO this paragraph is necessary, but not sure it works. # TODO this paragraph is necessary, but not sure it works.
context = self._user_context.get_context() context = self._user_context.get_context()
next(context) # skip the path next(context) # skip the path
if False and next(context) == 'from': if next(context) == 'from':
# completion is just "import" if before stands from .. # completion is just "import" if before stands from ..
completions += ((k, bs) for k in keywords.keyword_names('import')) completions += ((k, bs) for k in keywords.keyword_names('import'))
module = self._parser.module() module = self._parser.module()
name = user_stmt.name_for_position(self._pos) name = user_stmt.name_for_position(self._pos)
imp = imports.ImportWrapper(self._evaluator, name) if name is not None:
completions += [(n, module) for n in imp.completions()] imp = imports.ImportWrapper(self._evaluator, name)
completions += [(n, module) for n in imp.completion_names()]
if importer or isinstance(user_stmt, pr.Import): if importer or isinstance(user_stmt, pr.Import):
return completions return completions

View File

@@ -57,7 +57,7 @@ def importer_from_error_statement(evaluator, module, error_statement, pos):
elif typ == 'import_from': elif typ == 'import_from':
for node in nodes: for node in nodes:
if isinstance(node, pt.Node) and node.type == 'dotted_name': if isinstance(node, pt.Node) and node.type == 'dotted_name':
names += check_dotted(node.children[::2]) names += check_dotted(node.children)
elif node in ('.', '...'): elif node in ('.', '...'):
level += len(node.value) level += len(node.value)
elif isinstance(node, pt.Name) and node.end_pos < pos: elif isinstance(node, pt.Name) and node.end_pos < pos:

View File

@@ -47,7 +47,7 @@ class ImportWrapper(pr.Base):
self.import_path = self._import.path_for_name(name) self.import_path = self._import.path_for_name(name)
self.is_like_search = False # TODO REMOVE self.is_like_search = False # TODO REMOVE
def completions(self): def completion_names(self):
# The import path needs to be reduced by one, because we're completing. # The import path needs to be reduced by one, because we're completing.
import_path = self.import_path[:-1] import_path = self.import_path[:-1]
module = self._import.get_parent_until() module = self._import.get_parent_until()
@@ -628,28 +628,29 @@ class _Importer(object):
""" """
names = [] names = []
if self.import_path: if self.import_path:
for scope in self.follow(evaluator): # flask
# flask if self.str_import_path == ('flask', 'ext'):
if self.str_import_path == ('flask', 'ext'): # List Flask extensions like ``flask_foo``
# List Flask extensions like ``flask_foo`` for mod in self._get_module_names():
for mod in self._get_module_names(): modname = str(mod)
modname = str(mod) if modname.startswith('flask_'):
if modname.startswith('flask_'): extname = modname[len('flask_'):]
extname = modname[len('flask_'):] names.append(self._generate_name(extname))
names.append(self._generate_name(extname)) # Now the old style: ``flaskext.foo``
# Now the old style: ``flaskext.foo`` for dir in self.sys_path_with_modifications():
for dir in self.sys_path_with_modifications(): flaskext = os.path.join(dir, 'flaskext')
flaskext = os.path.join(dir, 'flaskext') if os.path.isdir(flaskext):
if os.path.isdir(flaskext): names += self._get_module_names([flaskext])
names += self._get_module_names([flaskext])
from jedi.evaluate import finder, representation as er
for scope in self.follow(evaluator):
# namespace packages # namespace packages
if isinstance(scope, pr.Module) and scope.path.endswith('__init__.py'): if isinstance(scope, pr.Module) and scope.path.endswith('__init__.py'):
pkg_path = os.path.dirname(scope.path) pkg_path = os.path.dirname(scope.path)
paths = self.namespace_packages(pkg_path, self.import_path) paths = self.namespace_packages(pkg_path, self.import_path)
names += self._get_module_names([pkg_path] + paths) names += self._get_module_names([pkg_path] + paths)
if only_modules: if only_modules or not isinstance(scope, er.ModuleWrapper):
# In the case of an import like `from x.` we don't need to # In the case of an import like `from x.` we don't need to
# add all the variables. # add all the variables.
if ('os',) == self.str_import_path and not self.level: if ('os',) == self.str_import_path and not self.level:
@@ -659,15 +660,6 @@ class _Importer(object):
continue continue
# TODO delete
if False and not self.import_stmt.from_names or False and self.is_partial_import:
# from_names must be defined to access module
# values plus a partial import means that there
# is something after the import, which
# automatically implies that there must not be
# any non-module scope.
continue
from jedi.evaluate import finder
for s, scope_names in finder.get_names_of_scope(self._evaluator, for s, scope_names in finder.get_names_of_scope(self._evaluator,
scope, include_builtin=False): scope, include_builtin=False):
for n in scope_names: for n in scope_names:

View File

@@ -61,10 +61,10 @@ import datetime.
#? [] #? []
import datetime.date import datetime.date
#? 17 ['import'] #? 21 ['import']
from import_tree import pkg from import_tree.pkg import pkg
#? 18 ['import', 'pkg'] #? 22 ['import', 'mod1']
from import_tree. import pkg from import_tree.pkg. import mod1
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2'] #? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2']
from import_tree. import pkg from import_tree. import pkg