mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Make Module::all_submodules
return Module
instead of Name
This is to facilitate recursive traversal of all modules in an environment. This way, we can keep asking for submodules. This also simplifies how this is used in completions, and probably makes it faster. Namely, since we return the `Module` itself, callers don't need to invoke the full module resolver just to get the module type. Note that this doesn't include namespace packages. (Which were previously not supported in `Module::all_submodules`.) Given how they can be spread out across multiple search paths, they will likely require special consideration here.
This commit is contained in:
parent
9cea752934
commit
046893c186
3 changed files with 74 additions and 37 deletions
|
@ -173,19 +173,10 @@ impl<'db> SemanticModel<'db> {
|
|||
let builtin = module.is_known(self.db, KnownModule::Builtins);
|
||||
|
||||
let mut completions = vec![];
|
||||
for submodule_basename in module.all_submodules(self.db) {
|
||||
let Some(basename) = ModuleName::new(submodule_basename.as_str()) else {
|
||||
continue;
|
||||
};
|
||||
let mut submodule_name = module.name(self.db).clone();
|
||||
submodule_name.extend(&basename);
|
||||
|
||||
let Some(submodule) = resolve_module(self.db, &submodule_name) else {
|
||||
continue;
|
||||
};
|
||||
let ty = Type::module_literal(self.db, self.file, submodule);
|
||||
for submodule in module.all_submodules(self.db) {
|
||||
let ty = Type::module_literal(self.db, self.file, *submodule);
|
||||
completions.push(Completion {
|
||||
name: submodule_basename.clone(),
|
||||
name: Name::new(submodule.name(self.db).as_str()),
|
||||
ty,
|
||||
builtin,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue