This commit is contained in:
Aleksey Kladov 2019-01-25 10:29:00 +03:00
parent ed27bd8d77
commit 74beb5bfcb
5 changed files with 20 additions and 14 deletions

View File

@ -29,6 +29,10 @@ impl<ID: ArenaId, T> ArenaMap<ID, T> {
self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref())
}
pub fn get_mut(&mut self, id: ID) -> Option<&mut T> {
self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut())
}
pub fn values(&self) -> impl Iterator<Item = &T> {
self.v.iter().filter_map(|o| o.as_ref())
}

View File

@ -165,7 +165,7 @@ impl Module {
/// Returns a `ModuleScope`: a set of items, visible in this module.
pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope {
self.scope_impl(db)
db.item_map(self.krate)[self.module_id].clone()
}
pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<ModuleDef> {

View File

@ -2,10 +2,10 @@ use ra_db::FileId;
use ra_syntax::{ast, SyntaxNode, TreeArc};
use crate::{
Module, ModuleSource, Problem, ModuleDef,
Crate, Name, Path, PerNs,
Module, ModuleSource, Problem,
Crate, Name,
module_tree::ModuleId,
nameres::{ModuleScope, lower::ImportId},
nameres::{lower::ImportId},
db::HirDatabase,
};
@ -90,12 +90,6 @@ impl Module {
Some(self.with_module_id(parent_id))
}
/// Returns a `ModuleScope`: a set of items, visible in this module.
pub(crate) fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope {
let item_map = db.item_map(self.krate);
item_map.per_module[&self.module_id].clone()
}
pub(crate) fn problems_impl(
&self,
db: &impl HirDatabase,

View File

@ -19,6 +19,7 @@ pub(crate) mod lower;
use std::sync::Arc;
use ra_db::CrateId;
use ra_arena::map::ArenaMap;
use test_utils::tested_by;
use rustc_hash::{FxHashMap, FxHashSet};
@ -37,7 +38,14 @@ use crate::{
// FIXME: currenty we compute item map per source-root. We should do it per crate instead.
#[derive(Default, Debug, PartialEq, Eq)]
pub struct ItemMap {
pub per_module: FxHashMap<ModuleId, ModuleScope>,
per_module: ArenaMap<ModuleId, ModuleScope>,
}
impl std::ops::Index<ModuleId> for ItemMap {
type Output = ModuleScope;
fn index(&self, id: ModuleId) -> &ModuleScope {
&self.per_module[id]
}
}
#[derive(Debug, Default, PartialEq, Eq, Clone)]
@ -308,7 +316,7 @@ where
}
fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) {
let module_items = self.result.per_module.get_mut(&module_id).unwrap();
let module_items = self.result.per_module.get_mut(module_id).unwrap();
f(module_items)
}
}
@ -380,7 +388,7 @@ impl ItemMap {
return (def, ReachedFixedPoint::Yes);
}
match self.per_module[&module.module_id].items.get(&segment.name) {
match self[module.module_id].items.get(&segment.name) {
Some(res) if !res.def.is_none() => res.def,
_ => {
log::debug!("path segment {:?} not found", segment.name);

View File

@ -20,7 +20,7 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
}
fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) {
let mut lines = map.per_module[&module_id]
let mut lines = map[module_id]
.items
.iter()
.map(|(name, res)| format!("{}: {}", name, dump_resolution(res)))