diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 09:16:07 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 09:16:07 +0000 |
commit | 9a16cf2bf646a4a881f3f5acbf5582dacc4337bf (patch) | |
tree | ff90eb390a8f5af47b6d0c6ec4c49b4431b82d1c /crates/ra_hir/src/module/nameres.rs | |
parent | dbb62b5baa36783bbca06f09c77794fce3ceff0c (diff) | |
parent | a084412f0698d5f54d586f707930e141c88b0673 (diff) |
Merge #292
292: Vfs r=matklad a=matklad
closes #243
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/module/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/module/nameres.rs | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index 5540b827f..f44abc730 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs | |||
@@ -32,11 +32,12 @@ use crate::{ | |||
32 | SourceItemId, SourceFileItemId, SourceFileItems, | 32 | SourceItemId, SourceFileItemId, SourceFileItems, |
33 | Path, PathKind, | 33 | Path, PathKind, |
34 | HirDatabase, Crate, | 34 | HirDatabase, Crate, |
35 | module::{ModuleId, ModuleTree}, | 35 | module::{Module, ModuleId, ModuleTree}, |
36 | }; | 36 | }; |
37 | 37 | ||
38 | /// Item map is the result of the name resolution. Item map contains, for each | 38 | /// Item map is the result of the name resolution. Item map contains, for each |
39 | /// module, the set of visible items. | 39 | /// module, the set of visible items. |
40 | // FIXME: currenty we compute item map per source-root. We should do it per crate instead. | ||
40 | #[derive(Default, Debug, PartialEq, Eq)] | 41 | #[derive(Default, Debug, PartialEq, Eq)] |
41 | pub struct ItemMap { | 42 | pub struct ItemMap { |
42 | pub per_module: FxHashMap<ModuleId, ModuleScope>, | 43 | pub per_module: FxHashMap<ModuleId, ModuleScope>, |
@@ -252,7 +253,8 @@ where | |||
252 | let krate = Crate::new(crate_id); | 253 | let krate = Crate::new(crate_id); |
253 | for dep in krate.dependencies(self.db) { | 254 | for dep in krate.dependencies(self.db) { |
254 | if let Some(module) = dep.krate.root_module(self.db)? { | 255 | if let Some(module) = dep.krate.root_module(self.db)? { |
255 | self.add_module_item(&mut module_items, dep.name, module.module_id); | 256 | let def_id = module.def_id(self.db); |
257 | self.add_module_item(&mut module_items, dep.name, def_id); | ||
256 | } | 258 | } |
257 | } | 259 | } |
258 | }; | 260 | }; |
@@ -294,21 +296,21 @@ where | |||
294 | 296 | ||
295 | // Populate modules | 297 | // Populate modules |
296 | for (name, module_id) in module_id.children(&self.module_tree) { | 298 | for (name, module_id) in module_id.children(&self.module_tree) { |
297 | self.add_module_item(&mut module_items, name, module_id); | 299 | let def_loc = DefLoc { |
300 | kind: DefKind::Module, | ||
301 | source_root_id: self.source_root, | ||
302 | module_id, | ||
303 | source_item_id: module_id.source(&self.module_tree).0, | ||
304 | }; | ||
305 | let def_id = def_loc.id(self.db); | ||
306 | self.add_module_item(&mut module_items, name, def_id); | ||
298 | } | 307 | } |
299 | 308 | ||
300 | self.result.per_module.insert(module_id, module_items); | 309 | self.result.per_module.insert(module_id, module_items); |
301 | Ok(()) | 310 | Ok(()) |
302 | } | 311 | } |
303 | 312 | ||
304 | fn add_module_item(&self, module_items: &mut ModuleScope, name: SmolStr, module_id: ModuleId) { | 313 | fn add_module_item(&self, module_items: &mut ModuleScope, name: SmolStr, def_id: DefId) { |
305 | let def_loc = DefLoc { | ||
306 | kind: DefKind::Module, | ||
307 | source_root_id: self.source_root, | ||
308 | module_id, | ||
309 | source_item_id: module_id.source(&self.module_tree).0, | ||
310 | }; | ||
311 | let def_id = def_loc.id(self.db); | ||
312 | let resolution = Resolution { | 314 | let resolution = Resolution { |
313 | def_id: Some(def_id), | 315 | def_id: Some(def_id), |
314 | import: None, | 316 | import: None, |
@@ -329,7 +331,7 @@ where | |||
329 | ImportKind::Named(ptr) => ptr, | 331 | ImportKind::Named(ptr) => ptr, |
330 | }; | 332 | }; |
331 | 333 | ||
332 | let mut curr = match import.path.kind { | 334 | let mut curr: ModuleId = match import.path.kind { |
333 | PathKind::Plain | PathKind::Self_ => module_id, | 335 | PathKind::Plain | PathKind::Self_ => module_id, |
334 | PathKind::Super => { | 336 | PathKind::Super => { |
335 | match module_id.parent(&self.module_tree) { | 337 | match module_id.parent(&self.module_tree) { |
@@ -356,9 +358,30 @@ where | |||
356 | curr = match def_id.loc(self.db) { | 358 | curr = match def_id.loc(self.db) { |
357 | DefLoc { | 359 | DefLoc { |
358 | kind: DefKind::Module, | 360 | kind: DefKind::Module, |
359 | module_id, | 361 | module_id: target_module_id, |
362 | source_root_id, | ||
360 | .. | 363 | .. |
361 | } => module_id, | 364 | } => { |
365 | if source_root_id == self.source_root { | ||
366 | target_module_id | ||
367 | } else { | ||
368 | let module = Module::new(self.db, source_root_id, target_module_id)?; | ||
369 | let path = Path { | ||
370 | segments: import.path.segments[i + 1..].iter().cloned().collect(), | ||
371 | kind: PathKind::Crate, | ||
372 | }; | ||
373 | if let Some(def_id) = module.resolve_path(self.db, path)? { | ||
374 | self.update(module_id, |items| { | ||
375 | let res = Resolution { | ||
376 | def_id: Some(def_id), | ||
377 | import: Some(ptr), | ||
378 | }; | ||
379 | items.items.insert(name.clone(), res); | ||
380 | }) | ||
381 | } | ||
382 | return Ok(()); | ||
383 | } | ||
384 | } | ||
362 | _ => return Ok(()), | 385 | _ => return Ok(()), |
363 | } | 386 | } |
364 | } else { | 387 | } else { |