mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
ra_hir: expose import_map::search_dependencies
This commit is contained in:
parent
6463d3ac63
commit
b01fb22494
1 changed files with 14 additions and 0 deletions
|
@ -9,6 +9,7 @@ use hir_def::{
|
|||
builtin_type::BuiltinType,
|
||||
docs::Documentation,
|
||||
expr::{BindingAnnotation, Pat, PatId},
|
||||
import_map,
|
||||
per_ns::PerNs,
|
||||
resolver::{HasResolver, Resolver},
|
||||
type_ref::{Mutability, TypeRef},
|
||||
|
@ -98,6 +99,19 @@ impl Crate {
|
|||
db.crate_graph()[self.id].display_name.as_ref().cloned()
|
||||
}
|
||||
|
||||
pub fn query_external_importables(
|
||||
self,
|
||||
db: &dyn DefDatabase,
|
||||
query: &str,
|
||||
) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
|
||||
import_map::search_dependencies(db, self.into(), import_map::Query::new(query).anchor_end())
|
||||
.into_iter()
|
||||
.map(|item| match item {
|
||||
ItemInNs::Types(mod_id) | ItemInNs::Values(mod_id) => Either::Left(mod_id.into()),
|
||||
ItemInNs::Macros(mac_id) => Either::Right(mac_id.into()),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn all(db: &dyn HirDatabase) -> Vec<Crate> {
|
||||
db.crate_graph().iter().map(|id| Crate { id }).collect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue