diff options
author | Aleksey Kladov <[email protected]> | 2019-03-14 09:54:03 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-03-17 09:52:05 +0000 |
commit | c7259a899c1709753dcda0fb117e2f7cc30a4d6e (patch) | |
tree | 410be0a8db17aca2d9878b0b2ac36d1921660990 /crates/ra_hir/src/nameres/crate_def_map.rs | |
parent | 71e5adf694a4b253bc5bb48be96bb6ba08002d8c (diff) |
remove ItemMap
Diffstat (limited to 'crates/ra_hir/src/nameres/crate_def_map.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/crate_def_map.rs | 30 |
1 files changed, 24 insertions, 6 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 { |