aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/crate_def_map.rs30
-rw-r--r--crates/ra_hir/src/nameres/crate_def_map/collector.rs10
2 files changed, 29 insertions, 11 deletions
diff --git a/crates/ra_hir/src/nameres/crate_def_map.rs b/crates/ra_hir/src/nameres/crate_def_map.rs
index 37b36719f..cc4955053 100644
--- a/crates/ra_hir/src/nameres/crate_def_map.rs
+++ b/crates/ra_hir/src/nameres/crate_def_map.rs
@@ -149,8 +149,16 @@ impl CrateDefMap {
149 &self.problems 149 &self.problems
150 } 150 }
151 151
152 pub(crate) fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { 152 pub(crate) fn mk_module(&self, module_id: ModuleId) -> Module {
153 self.modules.iter().map(|(id, _data)| id) 153 Module { krate: self.krate, module_id }
154 }
155
156 pub(crate) fn prelude(&self) -> Option<Module> {
157 self.prelude
158 }
159
160 pub(crate) fn extern_prelude(&self) -> &FxHashMap<Name, ModuleDef> {
161 &self.extern_prelude
154 } 162 }
155 163
156 pub(crate) fn find_module_by_source( 164 pub(crate) fn find_module_by_source(
@@ -169,6 +177,16 @@ impl CrateDefMap {
169 Some(module_id) 177 Some(module_id)
170 } 178 }
171 179
180 pub(crate) fn resolve_path(
181 &self,
182 db: &impl PersistentHirDatabase,
183 original_module: ModuleId,
184 path: &Path,
185 ) -> (PerNs<ModuleDef>, Option<usize>) {
186 let res = self.resolve_path_fp(db, ResolveMode::Other, original_module, path);
187 (res.resolved_def, res.segment_index)
188 }
189
172 // Returns Yes if we are sure that additions to `ItemMap` wouldn't change 190 // Returns Yes if we are sure that additions to `ItemMap` wouldn't change
173 // the result. 191 // the result.
174 fn resolve_path_fp( 192 fn resolve_path_fp(
@@ -254,8 +272,8 @@ impl CrateDefMap {
254 kind: PathKind::Self_, 272 kind: PathKind::Self_,
255 }; 273 };
256 log::debug!("resolving {:?} in other crate", path); 274 log::debug!("resolving {:?} in other crate", path);
257 let item_map = db.item_map(module.krate); 275 let defp_map = db.crate_def_map(module.krate);
258 let (def, s) = item_map.resolve_path(db, *module, &path); 276 let (def, s) = defp_map.resolve_path(db, module.module_id, &path);
259 return ResolvePathResult::with( 277 return ResolvePathResult::with(
260 def, 278 def,
261 ReachedFixedPoint::Yes, 279 ReachedFixedPoint::Yes,
@@ -313,7 +331,7 @@ impl CrateDefMap {
313 from_crate_root.or(from_extern_prelude) 331 from_crate_root.or(from_extern_prelude)
314 } 332 }
315 333
316 fn resolve_name_in_module( 334 pub(crate) fn resolve_name_in_module(
317 &self, 335 &self,
318 db: &impl PersistentHirDatabase, 336 db: &impl PersistentHirDatabase,
319 module: ModuleId, 337 module: ModuleId,
@@ -340,7 +358,7 @@ impl CrateDefMap {
340 let resolution = if prelude.krate == self.krate { 358 let resolution = if prelude.krate == self.krate {
341 self[prelude.module_id].scope.items.get(name).cloned() 359 self[prelude.module_id].scope.items.get(name).cloned()
342 } else { 360 } else {
343 db.item_map(prelude.krate)[prelude.module_id].items.get(name).cloned() 361 db.crate_def_map(prelude.krate)[prelude.module_id].scope.items.get(name).cloned()
344 }; 362 };
345 resolution.map(|r| r.def).unwrap_or_else(PerNs::none) 363 resolution.map(|r| r.def).unwrap_or_else(PerNs::none)
346 } else { 364 } else {
diff --git a/crates/ra_hir/src/nameres/crate_def_map/collector.rs b/crates/ra_hir/src/nameres/crate_def_map/collector.rs
index 68f74b866..8b727e2c9 100644
--- a/crates/ra_hir/src/nameres/crate_def_map/collector.rs
+++ b/crates/ra_hir/src/nameres/crate_def_map/collector.rs
@@ -26,9 +26,9 @@ pub(super) fn collect_defs(
26 } 26 }
27 // look for the prelude 27 // look for the prelude
28 if def_map.prelude.is_none() { 28 if def_map.prelude.is_none() {
29 let item_map = db.item_map(dep.krate); 29 let map = db.crate_def_map(dep.krate);
30 if item_map.prelude.is_some() { 30 if map.prelude.is_some() {
31 def_map.prelude = item_map.prelude; 31 def_map.prelude = map.prelude;
32 } 32 }
33 } 33 }
34 } 34 }
@@ -162,8 +162,8 @@ where
162 } else if m.krate != self.def_map.krate { 162 } else if m.krate != self.def_map.krate {
163 tested_by!(glob_across_crates); 163 tested_by!(glob_across_crates);
164 // glob import from other crate => we can just import everything once 164 // glob import from other crate => we can just import everything once
165 let item_map = self.db.item_map(m.krate); 165 let item_map = self.db.crate_def_map(m.krate);
166 let scope = &item_map[m.module_id]; 166 let scope = &item_map[m.module_id].scope;
167 let items = scope 167 let items = scope
168 .items 168 .items
169 .iter() 169 .iter()