diff options
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 57e7d0b9a..59af4ec60 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -4,10 +4,10 @@ use std::sync::Arc; | |||
4 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | ModuleDef, Module, | 7 | ModuleDef, |
8 | db::HirDatabase, | 8 | db::HirDatabase, |
9 | name::{Name, KnownName}, | 9 | name::{Name, KnownName}, |
10 | nameres::{PerNs, ItemMap}, | 10 | nameres::{PerNs, CrateDefMap, CrateModuleId}, |
11 | generics::GenericParams, | 11 | generics::GenericParams, |
12 | expr::{scope::{ExprScopes, ScopeId}, PatId, Body}, | 12 | expr::{scope::{ExprScopes, ScopeId}, PatId, Body}, |
13 | impl_block::ImplBlock, | 13 | impl_block::ImplBlock, |
@@ -22,8 +22,8 @@ pub struct Resolver { | |||
22 | // TODO how to store these best | 22 | // TODO how to store these best |
23 | #[derive(Debug, Clone)] | 23 | #[derive(Debug, Clone)] |
24 | pub(crate) struct ModuleItemMap { | 24 | pub(crate) struct ModuleItemMap { |
25 | item_map: Arc<ItemMap>, | 25 | crate_def_map: Arc<CrateDefMap>, |
26 | module: Module, | 26 | module_id: CrateModuleId, |
27 | } | 27 | } |
28 | 28 | ||
29 | #[derive(Debug, Clone)] | 29 | #[derive(Debug, Clone)] |
@@ -175,9 +175,9 @@ impl Resolver { | |||
175 | names | 175 | names |
176 | } | 176 | } |
177 | 177 | ||
178 | fn module(&self) -> Option<(&ItemMap, Module)> { | 178 | fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> { |
179 | self.scopes.iter().rev().find_map(|scope| match scope { | 179 | self.scopes.iter().rev().find_map(|scope| match scope { |
180 | Scope::ModuleScope(m) => Some((&*m.item_map, m.module.clone())), | 180 | Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), |
181 | 181 | ||
182 | _ => None, | 182 | _ => None, |
183 | }) | 183 | }) |
@@ -206,8 +206,12 @@ impl Resolver { | |||
206 | self.push_scope(Scope::ImplBlockScope(impl_block)) | 206 | self.push_scope(Scope::ImplBlockScope(impl_block)) |
207 | } | 207 | } |
208 | 208 | ||
209 | pub(crate) fn push_module_scope(self, item_map: Arc<ItemMap>, module: Module) -> Resolver { | 209 | pub(crate) fn push_module_scope( |
210 | self.push_scope(Scope::ModuleScope(ModuleItemMap { item_map, module })) | 210 | self, |
211 | crate_def_map: Arc<CrateDefMap>, | ||
212 | module_id: CrateModuleId, | ||
213 | ) -> Resolver { | ||
214 | self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) | ||
211 | } | 215 | } |
212 | 216 | ||
213 | pub(crate) fn push_expr_scope( | 217 | pub(crate) fn push_expr_scope( |
@@ -224,9 +228,11 @@ impl Scope { | |||
224 | match self { | 228 | match self { |
225 | Scope::ModuleScope(m) => { | 229 | Scope::ModuleScope(m) => { |
226 | if let Some(KnownName::SelfParam) = name.as_known_name() { | 230 | if let Some(KnownName::SelfParam) = name.as_known_name() { |
227 | PerNs::types(Resolution::Def(m.module.into())) | 231 | PerNs::types(Resolution::Def(m.crate_def_map.mk_module(m.module_id).into())) |
228 | } else { | 232 | } else { |
229 | m.item_map.resolve_name_in_module(db, m.module, name).map(Resolution::Def) | 233 | m.crate_def_map |
234 | .resolve_name_in_module(db, m.module_id, name) | ||
235 | .map(Resolution::Def) | ||
230 | } | 236 | } |
231 | } | 237 | } |
232 | Scope::GenericParams(gp) => match gp.find_by_name(name) { | 238 | Scope::GenericParams(gp) => match gp.find_by_name(name) { |
@@ -261,15 +267,15 @@ impl Scope { | |||
261 | // def: m.module.into(), | 267 | // def: m.module.into(), |
262 | // }), | 268 | // }), |
263 | // ); | 269 | // ); |
264 | m.item_map[m.module.module_id].entries().for_each(|(name, res)| { | 270 | m.crate_def_map[m.module_id].scope.entries().for_each(|(name, res)| { |
265 | f(name.clone(), res.def.map(Resolution::Def)); | 271 | f(name.clone(), res.def.map(Resolution::Def)); |
266 | }); | 272 | }); |
267 | m.item_map.extern_prelude.iter().for_each(|(name, def)| { | 273 | m.crate_def_map.extern_prelude().iter().for_each(|(name, def)| { |
268 | f(name.clone(), PerNs::types(Resolution::Def(*def))); | 274 | f(name.clone(), PerNs::types(Resolution::Def(*def))); |
269 | }); | 275 | }); |
270 | if let Some(prelude) = m.item_map.prelude { | 276 | if let Some(prelude) = m.crate_def_map.prelude() { |
271 | let prelude_item_map = db.item_map(prelude.krate); | 277 | let prelude_def_map = db.crate_def_map(prelude.krate); |
272 | prelude_item_map[prelude.module_id].entries().for_each(|(name, res)| { | 278 | prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| { |
273 | f(name.clone(), res.def.map(Resolution::Def)); | 279 | f(name.clone(), res.def.map(Resolution::Def)); |
274 | }); | 280 | }); |
275 | } | 281 | } |