Use sub_module_dict for completing modules, not its own function

This commit is contained in:
Dave Halter
2019-05-06 09:19:33 +02:00
parent afced5014c
commit c675e85d69
4 changed files with 25 additions and 24 deletions

View File

@@ -2,7 +2,6 @@ import re
import os
from jedi.evaluate.cache import evaluator_method_cache
from jedi._compatibility import iter_modules
from jedi.evaluate.filters import GlobalNameFilter, ContextNameMixin, \
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
from jedi.evaluate import compiled
@@ -50,11 +49,10 @@ class SubModuleDictMixin(object):
except AttributeError:
pass
else:
for path in method():
mods = self._iter_modules(path)
for module_loader, name, is_pkg in mods:
# It's obviously a relative import to the current module.
names[name] = SubModuleName(self, name)
mods = self._iter_module_names(method())
for name in mods:
# It's obviously a relative import to the current module.
names[name] = SubModuleName(self, name)
# TODO add something like this in the future, its cleaner than the
# import hacks.
@@ -65,8 +63,8 @@ class SubModuleDictMixin(object):
return names
def _iter_modules(self, path):
return iter_modules([path])
def _iter_module_names(self, path):
return self.evaluator.compiled_subprocess.list_module_names(path)
class ModuleMixin(SubModuleDictMixin):

View File

@@ -31,7 +31,7 @@ class ImplicitNamespaceContext(Context, SubModuleDictMixin):
self._paths = paths
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
yield DictFilter(self._sub_modules_dict())
yield DictFilter(self.sub_modules_dict())
@property
@evaluator_method_cache()

View File

@@ -66,14 +66,16 @@ class StubModuleContext(_StubContextMixin, ModuleContext):
for f in filters:
yield f
def _iter_modules(self, path):
dirs = os.listdir(path)
for name in dirs:
if os.path.isdir(os.path.join(path, name)):
yield (None, name, True)
if name.endswith('.pyi'):
yield (None, name[:-4], True)
return []
def _iter_module_names(self, paths):
for path in paths:
dirs = os.listdir(path)
for name in dirs:
if os.path.isdir(os.path.join(path, name)):
if name != '__pycache__':
yield name
if name.endswith('.pyi'):
if name != '__init__.pyi':
yield name[:-4]
class StubClass(_StubContextMixin, ClassMixin, ContextWrapper):

View File

@@ -393,14 +393,15 @@ class Importer(object):
# Non-modules are not completable.
if context.api_type != 'module': # not a module
continue
names += context.sub_modules_dict().values()
# namespace packages
try:
path_method = context.py__path__
except AttributeError:
pass
else:
# For implicit namespace packages and module names.
names += self._get_module_names(path_method(), in_module=context)
#try:
# path_method = context.py__path__
#except AttributeError:
# pass
#else:
# # For implicit namespace packages and module names.
# names += self._get_module_names(path_method(), in_module=context)
if only_modules:
# In the case of an import like `from x.` we don't need to