Skip to content

Commit b01fb22

Browse files
author
Jonas Schievink
committed
ra_hir: expose import_map::search_dependencies
1 parent 6463d3a commit b01fb22

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use hir_def::{
99
builtin_type::BuiltinType,
1010
docs::Documentation,
1111
expr::{BindingAnnotation, Pat, PatId},
12+
import_map,
1213
per_ns::PerNs,
1314
resolver::{HasResolver, Resolver},
1415
type_ref::{Mutability, TypeRef},
@@ -98,6 +99,19 @@ impl Crate {
9899
db.crate_graph()[self.id].display_name.as_ref().cloned()
99100
}
100101

102+
pub fn query_external_importables(
103+
self,
104+
db: &dyn DefDatabase,
105+
query: &str,
106+
) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
107+
import_map::search_dependencies(db, self.into(), import_map::Query::new(query).anchor_end())
108+
.into_iter()
109+
.map(|item| match item {
110+
ItemInNs::Types(mod_id) | ItemInNs::Values(mod_id) => Either::Left(mod_id.into()),
111+
ItemInNs::Macros(mac_id) => Either::Right(mac_id.into()),
112+
})
113+
}
114+
101115
pub fn all(db: &dyn HirDatabase) -> Vec<Crate> {
102116
db.crate_graph().iter().map(|id| Crate { id }).collect()
103117
}

0 commit comments

Comments
 (0)