From 65c064b2a99fb9c0589672ae6c9848aaa9e0efcf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 02:22:25 +0300 Subject: introduce SymbolsDatabase --- crates/ra_analysis/src/db.rs | 28 +++++++++++----------------- crates/ra_analysis/src/imp.rs | 4 ++-- crates/ra_analysis/src/input.rs | 6 +----- crates/ra_analysis/src/symbol_index.rs | 29 ++++++++++++++++++++++++++--- 4 files changed, 40 insertions(+), 27 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 4c9c84e4f..0901c2bba 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -7,7 +7,7 @@ use salsa::{self, Database}; use crate::{ hir, - symbol_index::SymbolIndex, + symbol_index, loc2id::{IdMaps}, Cancelable, Canceled, FileId, }; @@ -114,23 +114,25 @@ salsa::database_storage! { fn file_source_root() for crate::input::FileSourceRootQuery; fn source_root() for crate::input::SourceRootQuery; fn libraries() for crate::input::LibrariesQuery; - fn library_symbols() for crate::input::LibrarySymbolsQuery; fn crate_graph() for crate::input::CrateGraphQuery; } impl SyntaxDatabase { fn file_syntax() for FileSyntaxQuery; fn file_lines() for FileLinesQuery; - fn file_symbols() for FileSymbolsQuery; + } + impl symbol_index::SymbolsDatabase { + fn file_symbols() for symbol_index::FileSymbolsQuery; + fn library_symbols() for symbol_index::LibrarySymbolsQuery; } impl hir::db::HirDatabase { fn module_tree() for hir::db::ModuleTreeQuery; fn fn_scopes() for hir::db::FnScopesQuery; - fn _file_items() for hir::db::SourceFileItemsQuery; - fn _file_item() for hir::db::FileItemQuery; - fn _input_module_items() for hir::db::InputModuleItemsQuery; - fn _item_map() for hir::db::ItemMapQuery; - fn _fn_syntax() for hir::db::FnSyntaxQuery; - fn _submodules() for hir::db::SubmodulesQuery; + fn file_items() for hir::db::SourceFileItemsQuery; + fn file_item() for hir::db::FileItemQuery; + fn input_module_items() for hir::db::InputModuleItemsQuery; + fn item_map() for hir::db::ItemMapQuery; + fn fn_syntax() for hir::db::FnSyntaxQuery; + fn submodules() for hir::db::SubmodulesQuery; } } } @@ -143,9 +145,6 @@ salsa::query_group! { fn file_lines(file_id: FileId) -> Arc { type FileLinesQuery; } - fn file_symbols(file_id: FileId) -> Cancelable> { - type FileSymbolsQuery; - } } } @@ -157,8 +156,3 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc { let text = db.file_text(file_id); Arc::new(LineIndex::new(&*text)) } -fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable> { - db.check_canceled()?; - let syntax = db.file_syntax(file_id); - Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) -} diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 2e5853949..e3b78bb1a 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -25,7 +25,7 @@ use crate::{ Problem, }, input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, - symbol_index::SymbolIndex, + symbol_index::{SymbolIndex, SymbolsDatabase}, AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, }; @@ -161,7 +161,7 @@ impl AnalysisHostImpl { .query_mut(crate::input::SourceRootQuery) .set(source_root_id, Arc::new(source_root)); self.db - .query_mut(crate::input::LibrarySymbolsQuery) + .query_mut(crate::symbol_index::LibrarySymbolsQuery) .set(source_root_id, Arc::new(library.symbol_index)); } self.db diff --git a/crates/ra_analysis/src/input.rs b/crates/ra_analysis/src/input.rs index 60086d1ae..e601cd58a 100644 --- a/crates/ra_analysis/src/input.rs +++ b/crates/ra_analysis/src/input.rs @@ -5,7 +5,7 @@ use rustc_hash::FxHashMap; use rustc_hash::FxHashSet; use salsa; -use crate::{symbol_index::SymbolIndex, FileResolverImp}; +use crate::FileResolverImp; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FileId(pub u32); @@ -56,10 +56,6 @@ salsa::query_group! { type LibrariesQuery; storage input; } - fn library_symbols(id: SourceRootId) -> Arc { - type LibrarySymbolsQuery; - storage input; - } fn crate_graph() -> Arc { type CrateGraphQuery; storage input; diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index 3a0667ecd..a6937d7f2 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs @@ -4,14 +4,37 @@ use std::{ }; use fst::{self, Streamer}; -use ra_editor::{file_symbols, FileSymbol}; +use ra_editor::{self, FileSymbol}; use ra_syntax::{ SourceFileNode, SyntaxKind::{self, *}, }; use rayon::prelude::*; -use crate::{FileId, Query}; +use crate::{ + Cancelable, + FileId, Query, + db::SyntaxDatabase, + input::SourceRootId, +}; + +salsa::query_group! { + pub(crate) trait SymbolsDatabase: SyntaxDatabase { + fn file_symbols(file_id: FileId) -> Cancelable> { + type FileSymbolsQuery; + } + fn library_symbols(id: SourceRootId) -> Arc { + type LibrarySymbolsQuery; + storage input; + } + } +} + +fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable> { + db.check_canceled()?; + let syntax = db.file_syntax(file_id); + Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) +} #[derive(Default, Debug)] pub(crate) struct SymbolIndex { @@ -39,7 +62,7 @@ impl SymbolIndex { ) -> SymbolIndex { let mut symbols = files .flat_map(|(file_id, file)| { - file_symbols(&file) + ra_editor::file_symbols(&file) .into_iter() .map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol))) .collect::>() -- cgit v1.2.3