aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/lang_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/lang_item.rs')
-rw-r--r--crates/ra_hir/src/lang_item.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs
index a25d419e7..5f3f91cba 100644
--- a/crates/ra_hir/src/lang_item.rs
+++ b/crates/ra_hir/src/lang_item.rs
@@ -40,7 +40,7 @@ impl LangItems {
40 self.items.get(item) 40 self.items.get(item)
41 } 41 }
42 42
43 /// Salsa query. This will query a specific crate for lang items. 43 /// Salsa query. This will look for lang items in a specific crate.
44 pub(crate) fn lang_items_query(db: &impl DefDatabase, krate: Crate) -> Arc<LangItems> { 44 pub(crate) fn lang_items_query(db: &impl DefDatabase, krate: Crate) -> Arc<LangItems> {
45 let mut lang_items = LangItems { items: FxHashMap::default() }; 45 let mut lang_items = LangItems { items: FxHashMap::default() };
46 46
@@ -51,6 +51,29 @@ impl LangItems {
51 Arc::new(lang_items) 51 Arc::new(lang_items)
52 } 52 }
53 53
54 /// Salsa query. Look for a lang item, starting from the specified crate and recursively
55 /// traversing its dependencies.
56 pub(crate) fn lang_item_query(
57 db: &impl DefDatabase,
58 start_crate: Crate,
59 item: SmolStr,
60 ) -> Option<LangItemTarget> {
61 let lang_items = db.lang_items(start_crate);
62 let start_crate_target = lang_items.items.get(&item);
63 if let Some(target) = start_crate_target {
64 Some(*target)
65 } else {
66 for dep in start_crate.dependencies(db) {
67 let dep_crate = dep.krate;
68 let dep_target = db.lang_item(dep_crate, item.clone());
69 if dep_target.is_some() {
70 return dep_target;
71 }
72 }
73 None
74 }
75 }
76
54 fn collect_lang_items_recursive(&mut self, db: &impl DefDatabase, module: &Module) { 77 fn collect_lang_items_recursive(&mut self, db: &impl DefDatabase, module: &Module) {
55 // Look for impl targets 78 // Look for impl targets
56 let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone()); 79 let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone());
@@ -77,26 +100,3 @@ impl LangItems {
77 } 100 }
78 } 101 }
79} 102}
80
81/// Look for a lang item, starting from the specified crate and recursively traversing its
82/// dependencies.
83pub(crate) fn lang_item_lookup(
84 db: &impl DefDatabase,
85 start_krate: Crate,
86 item: &str,
87) -> Option<LangItemTarget> {
88 let lang_items = db.lang_items(start_krate);
89 let start_krate_target = lang_items.items.get(item);
90 if start_krate_target.is_some() {
91 start_krate_target.map(|t| *t)
92 } else {
93 for dep in start_krate.dependencies(db) {
94 let dep_krate = dep.krate;
95 let dep_target = lang_item_lookup(db, dep_krate, item);
96 if dep_target.is_some() {
97 return dep_target;
98 }
99 }
100 None
101 }
102}