mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +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
|
import os
|
||||||
|
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi._compatibility import iter_modules
|
|
||||||
from jedi.evaluate.filters import GlobalNameFilter, ContextNameMixin, \
|
from jedi.evaluate.filters import GlobalNameFilter, ContextNameMixin, \
|
||||||
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
|
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
@@ -50,9 +49,8 @@ class SubModuleDictMixin(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for path in method():
|
mods = self._iter_module_names(method())
|
||||||
mods = self._iter_modules(path)
|
for name in mods:
|
||||||
for module_loader, name, is_pkg in mods:
|
|
||||||
# It's obviously a relative import to the current module.
|
# It's obviously a relative import to the current module.
|
||||||
names[name] = SubModuleName(self, name)
|
names[name] = SubModuleName(self, name)
|
||||||
|
|
||||||
@@ -65,8 +63,8 @@ class SubModuleDictMixin(object):
|
|||||||
|
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def _iter_modules(self, path):
|
def _iter_module_names(self, path):
|
||||||
return iter_modules([path])
|
return self.evaluator.compiled_subprocess.list_module_names(path)
|
||||||
|
|
||||||
|
|
||||||
class ModuleMixin(SubModuleDictMixin):
|
class ModuleMixin(SubModuleDictMixin):
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ImplicitNamespaceContext(Context, SubModuleDictMixin):
|
|||||||
self._paths = paths
|
self._paths = paths
|
||||||
|
|
||||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
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
|
@property
|
||||||
@evaluator_method_cache()
|
@evaluator_method_cache()
|
||||||
|
|||||||
@@ -66,14 +66,16 @@ class StubModuleContext(_StubContextMixin, ModuleContext):
|
|||||||
for f in filters:
|
for f in filters:
|
||||||
yield f
|
yield f
|
||||||
|
|
||||||
def _iter_modules(self, path):
|
def _iter_module_names(self, paths):
|
||||||
|
for path in paths:
|
||||||
dirs = os.listdir(path)
|
dirs = os.listdir(path)
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
if os.path.isdir(os.path.join(path, name)):
|
if os.path.isdir(os.path.join(path, name)):
|
||||||
yield (None, name, True)
|
if name != '__pycache__':
|
||||||
|
yield name
|
||||||
if name.endswith('.pyi'):
|
if name.endswith('.pyi'):
|
||||||
yield (None, name[:-4], True)
|
if name != '__init__.pyi':
|
||||||
return []
|
yield name[:-4]
|
||||||
|
|
||||||
|
|
||||||
class StubClass(_StubContextMixin, ClassMixin, ContextWrapper):
|
class StubClass(_StubContextMixin, ClassMixin, ContextWrapper):
|
||||||
|
|||||||
@@ -393,14 +393,15 @@ class Importer(object):
|
|||||||
# Non-modules are not completable.
|
# Non-modules are not completable.
|
||||||
if context.api_type != 'module': # not a module
|
if context.api_type != 'module': # not a module
|
||||||
continue
|
continue
|
||||||
|
names += context.sub_modules_dict().values()
|
||||||
# namespace packages
|
# namespace packages
|
||||||
try:
|
#try:
|
||||||
path_method = context.py__path__
|
# path_method = context.py__path__
|
||||||
except AttributeError:
|
#except AttributeError:
|
||||||
pass
|
# pass
|
||||||
else:
|
#else:
|
||||||
# For implicit namespace packages and module names.
|
# # For implicit namespace packages and module names.
|
||||||
names += self._get_module_names(path_method(), in_module=context)
|
# names += self._get_module_names(path_method(), in_module=context)
|
||||||
|
|
||||||
if only_modules:
|
if only_modules:
|
||||||
# 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
|
||||||
|
|||||||
Reference in New Issue
Block a user