From 36aad851383c7fd1ca5ffaa99ba8cc96b85378c1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 21 Nov 2018 00:39:50 +0300 Subject: add item map query --- crates/ra_analysis/src/db.rs | 5 +++-- crates/ra_analysis/src/descriptors/mod.rs | 6 +++++- crates/ra_analysis/src/descriptors/module/mod.rs | 2 +- crates/ra_analysis/src/descriptors/module/nameres.rs | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 8133b7875..cecce3447 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -8,7 +8,7 @@ use crate::{ db, descriptors::{ DescriptorDatabase, FnScopesQuery, FnSyntaxQuery, ModuleScopeQuery, ModuleTreeQuery, - SubmodulesQuery, + SubmodulesQuery, ItemMapQuery, }, symbol_index::SymbolIndex, syntax_ptr::SyntaxPtr, @@ -85,8 +85,9 @@ salsa::database_storage! { } impl DescriptorDatabase { fn module_tree() for ModuleTreeQuery; - fn module_scope() for ModuleScopeQuery; fn fn_scopes() for FnScopesQuery; + fn _item_map() for ItemMapQuery; + fn _module_scope() for ModuleScopeQuery; fn _fn_syntax() for FnSyntaxQuery; fn _submodules() for SubmodulesQuery; } diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs index a8489f89c..30bc5eca2 100644 --- a/crates/ra_analysis/src/descriptors/mod.rs +++ b/crates/ra_analysis/src/descriptors/mod.rs @@ -11,7 +11,7 @@ use ra_syntax::{ use crate::{ db::SyntaxDatabase, descriptors::function::{resolve_local_name, FnId, FnScopes}, - descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, + descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource, nameres::ItemMap}, input::SourceRootId, loc2id::IdDatabase, syntax_ptr::LocalSyntaxPtr, @@ -25,6 +25,10 @@ salsa::query_group! { use fn function::imp::fn_scopes; } + fn _item_map(source_root_id: SourceRootId) -> Cancelable> { + type ItemMapQuery; + use fn module::nameres::item_map; + } fn _module_tree(source_root_id: SourceRootId) -> Cancelable> { type ModuleTreeQuery; use fn module::imp::module_tree; diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 2d0bfa64c..124926a40 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -1,6 +1,6 @@ pub(super) mod imp; mod scope; -mod nameres; +pub(super) mod nameres; use std::sync::Arc; diff --git a/crates/ra_analysis/src/descriptors/module/nameres.rs b/crates/ra_analysis/src/descriptors/module/nameres.rs index 058e64ad1..657e5bd1c 100644 --- a/crates/ra_analysis/src/descriptors/module/nameres.rs +++ b/crates/ra_analysis/src/descriptors/module/nameres.rs @@ -9,6 +9,7 @@ use ra_syntax::{ }; use crate::{ + Cancelable, loc2id::{DefId, DefLoc}, descriptors::{ DescriptorDatabase, @@ -45,12 +46,21 @@ enum PathKind { Crate, } -#[derive(Debug)] -struct ItemMap { +pub(crate) fn item_map( + db: &impl DescriptorDatabase, + source_root: SourceRootId, +) -> Cancelable> { + unimplemented!() +} + +/// Item map is the result of the name resolution. Item map contains, for each +/// module, the set of visible items. +#[derive(Debug, PartialEq, Eq)] +pub(crate) struct ItemMap { per_module: FxHashMap, } -#[derive(Debug, Default)] +#[derive(Debug, Default, PartialEq, Eq)] struct ModuleItems { items: FxHashMap, import_resolutions: FxHashMap, @@ -58,7 +68,7 @@ struct ModuleItems { /// Resolution is basically `DefId` atm, but it should account for stuff like /// multiple namespaces, ambiguity and errors. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] struct Resolution { /// None for unresolved def_id: Option, -- cgit v1.2.3