mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Use sub_module_dict for completing modules, not its own function
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user