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/symbol_index.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'crates/ra_analysis/src/symbol_index.rs') 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