aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_arena/src/map.rs4
-rw-r--r--crates/ra_hir/src/code_model_api.rs2
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs12
-rw-r--r--crates/ra_hir/src/nameres.rs14
-rw-r--r--crates/ra_hir/src/nameres/tests.rs2
5 files changed, 20 insertions, 14 deletions
diff --git a/crates/ra_arena/src/map.rs b/crates/ra_arena/src/map.rs
index 2f09d677f..be80edaf3 100644
--- a/crates/ra_arena/src/map.rs
+++ b/crates/ra_arena/src/map.rs
@@ -29,6 +29,10 @@ impl<ID: ArenaId, T> ArenaMap<ID, T> {
29 self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref()) 29 self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref())
30 } 30 }
31 31
32 pub fn get_mut(&mut self, id: ID) -> Option<&mut T> {
33 self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut())
34 }
35
32 pub fn values(&self) -> impl Iterator<Item = &T> { 36 pub fn values(&self) -> impl Iterator<Item = &T> {
33 self.v.iter().filter_map(|o| o.as_ref()) 37 self.v.iter().filter_map(|o| o.as_ref())
34 } 38 }
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index e469c782e..a469ad477 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -165,7 +165,7 @@ impl Module {
165 165
166 /// Returns a `ModuleScope`: a set of items, visible in this module. 166 /// Returns a `ModuleScope`: a set of items, visible in this module.
167 pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope { 167 pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope {
168 self.scope_impl(db) 168 db.item_map(self.krate)[self.module_id].clone()
169 } 169 }
170 170
171 pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<ModuleDef> { 171 pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<ModuleDef> {
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index bf0e212ca..480ec27bf 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -2,10 +2,10 @@ use ra_db::FileId;
2use ra_syntax::{ast, SyntaxNode, TreeArc}; 2use ra_syntax::{ast, SyntaxNode, TreeArc};
3 3
4use crate::{ 4use crate::{
5 Module, ModuleSource, Problem, ModuleDef, 5 Module, ModuleSource, Problem,
6 Crate, Name, Path, PerNs, 6 Crate, Name,
7 module_tree::ModuleId, 7 module_tree::ModuleId,
8 nameres::{ModuleScope, lower::ImportId}, 8 nameres::{lower::ImportId},
9 db::HirDatabase, 9 db::HirDatabase,
10}; 10};
11 11
@@ -90,12 +90,6 @@ impl Module {
90 Some(self.with_module_id(parent_id)) 90 Some(self.with_module_id(parent_id))
91 } 91 }
92 92
93 /// Returns a `ModuleScope`: a set of items, visible in this module.
94 pub(crate) fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope {
95 let item_map = db.item_map(self.krate);
96 item_map.per_module[&self.module_id].clone()
97 }
98
99 pub(crate) fn problems_impl( 93 pub(crate) fn problems_impl(
100 &self, 94 &self,
101 db: &impl HirDatabase, 95 db: &impl HirDatabase,
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 32afd8e0a..88ad0a44d 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -19,6 +19,7 @@ pub(crate) mod lower;
19use std::sync::Arc; 19use std::sync::Arc;
20 20
21use ra_db::CrateId; 21use ra_db::CrateId;
22use ra_arena::map::ArenaMap;
22use test_utils::tested_by; 23use test_utils::tested_by;
23use rustc_hash::{FxHashMap, FxHashSet}; 24use rustc_hash::{FxHashMap, FxHashSet};
24 25
@@ -37,7 +38,14 @@ use crate::{
37// FIXME: currenty we compute item map per source-root. We should do it per crate instead. 38// FIXME: currenty we compute item map per source-root. We should do it per crate instead.
38#[derive(Default, Debug, PartialEq, Eq)] 39#[derive(Default, Debug, PartialEq, Eq)]
39pub struct ItemMap { 40pub struct ItemMap {
40 pub per_module: FxHashMap<ModuleId, ModuleScope>, 41 per_module: ArenaMap<ModuleId, ModuleScope>,
42}
43
44impl std::ops::Index<ModuleId> for ItemMap {
45 type Output = ModuleScope;
46 fn index(&self, id: ModuleId) -> &ModuleScope {
47 &self.per_module[id]
48 }
41} 49}
42 50
43#[derive(Debug, Default, PartialEq, Eq, Clone)] 51#[derive(Debug, Default, PartialEq, Eq, Clone)]
@@ -308,7 +316,7 @@ where
308 } 316 }
309 317
310 fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) { 318 fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) {
311 let module_items = self.result.per_module.get_mut(&module_id).unwrap(); 319 let module_items = self.result.per_module.get_mut(module_id).unwrap();
312 f(module_items) 320 f(module_items)
313 } 321 }
314} 322}
@@ -380,7 +388,7 @@ impl ItemMap {
380 return (def, ReachedFixedPoint::Yes); 388 return (def, ReachedFixedPoint::Yes);
381 } 389 }
382 390
383 match self.per_module[&module.module_id].items.get(&segment.name) { 391 match self[module.module_id].items.get(&segment.name) {
384 Some(res) if !res.def.is_none() => res.def, 392 Some(res) if !res.def.is_none() => res.def,
385 _ => { 393 _ => {
386 log::debug!("path segment {:?} not found", segment.name); 394 log::debug!("path segment {:?} not found", segment.name);
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 7e35c016f..c033bebe8 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -20,7 +20,7 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
20} 20}
21 21
22fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { 22fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) {
23 let mut lines = map.per_module[&module_id] 23 let mut lines = map[module_id]
24 .items 24 .items
25 .iter() 25 .iter()
26 .map(|(name, res)| format!("{}: {}", name, dump_resolution(res))) 26 .map(|(name, res)| format!("{}: {}", name, dump_resolution(res)))