aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-06-09 17:48:00 +0100
committerJonas Schievink <[email protected]>2020-06-10 11:38:58 +0100
commitb01fb22494eaf64c02c17fc38598a3a2dbd8e980 (patch)
treee1072f7300bd08f369056e2a25b6c602fc40405b
parent6463d3ac63a479e33d923593e720696b38a1a54c (diff)
ra_hir: expose `import_map::search_dependencies`
-rw-r--r--crates/ra_hir/src/code_model.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 4a06f3bcd..c8329d971 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -9,6 +9,7 @@ use hir_def::{
9 builtin_type::BuiltinType, 9 builtin_type::BuiltinType,
10 docs::Documentation, 10 docs::Documentation,
11 expr::{BindingAnnotation, Pat, PatId}, 11 expr::{BindingAnnotation, Pat, PatId},
12 import_map,
12 per_ns::PerNs, 13 per_ns::PerNs,
13 resolver::{HasResolver, Resolver}, 14 resolver::{HasResolver, Resolver},
14 type_ref::{Mutability, TypeRef}, 15 type_ref::{Mutability, TypeRef},
@@ -98,6 +99,19 @@ impl Crate {
98 db.crate_graph()[self.id].display_name.as_ref().cloned() 99 db.crate_graph()[self.id].display_name.as_ref().cloned()
99 } 100 }
100 101
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
101 pub fn all(db: &dyn HirDatabase) -> Vec<Crate> { 115 pub fn all(db: &dyn HirDatabase) -> Vec<Crate> {
102 db.crate_graph().iter().map(|id| Crate { id }).collect() 116 db.crate_graph().iter().map(|id| Crate { id }).collect()
103 } 117 }