From 5af9e475f4acce54f8383ed22febc412cf2541d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 1 Jun 2019 21:17:57 +0300 Subject: add AstDatabase --- crates/ra_hir/src/nameres/collector.rs | 15 +++++++++------ crates/ra_hir/src/nameres/raw.rs | 9 ++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir/src/nameres') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index af8ac064c..693c3fe8e 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -8,7 +8,7 @@ use ra_syntax::ast; use crate::{ Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef, - DefDatabase, HirFileId, Name, Path, + DefDatabase, HirFileId, Name, Path, AstDatabase, KnownName, nameres::{ Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, @@ -20,7 +20,10 @@ use crate::{ AstId, }; -pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { +pub(super) fn collect_defs( + db: &(impl DefDatabase + AstDatabase), + mut def_map: CrateDefMap, +) -> CrateDefMap { // populate external prelude for dep in def_map.krate.dependencies(db) { log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); @@ -93,7 +96,7 @@ struct DefCollector { impl<'a, DB> DefCollector<&'a DB> where - DB: DefDatabase, + DB: DefDatabase + AstDatabase, { fn collect(&mut self) { let crate_graph = self.db.crate_graph(); @@ -470,7 +473,7 @@ struct ModCollector<'a, D> { impl ModCollector<'_, &'_ mut DefCollector<&'_ DB>> where - DB: DefDatabase, + DB: DefDatabase + AstDatabase, { fn collect(&mut self, items: &[raw::RawItem]) { for item in items { @@ -615,7 +618,7 @@ fn is_macro_rules(path: &Path) -> bool { } fn resolve_submodule( - db: &impl DefDatabase, + db: &(impl DefDatabase + AstDatabase), file_id: HirFileId, name: &Name, is_root: bool, @@ -658,7 +661,7 @@ mod tests { use rustc_hash::FxHashSet; fn do_collect_defs( - db: &impl DefDatabase, + db: &(impl DefDatabase + AstDatabase), def_map: CrateDefMap, monitor: MacroStackMonitor, ) -> CrateDefMap { diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 1b4dcbb7a..21935dbb9 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -7,7 +7,7 @@ use ra_syntax::{ ast::{self, NameOwner, AttrsOwner}, }; -use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either}; +use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either, AstDatabase}; /// `RawItems` is a set of top-level items in a file (except for impls). /// @@ -56,12 +56,15 @@ impl ImportSourceMap { } impl RawItems { - pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc { + pub(crate) fn raw_items_query( + db: &(impl DefDatabase + AstDatabase), + file_id: HirFileId, + ) -> Arc { db.raw_items_with_source_map(file_id).0 } pub(crate) fn raw_items_with_source_map_query( - db: &impl DefDatabase, + db: &(impl DefDatabase + AstDatabase), file_id: HirFileId, ) -> (Arc, Arc) { let mut collector = RawItemsCollector { -- cgit v1.2.3