From a94530afb354d2f9a3e3864c678aa496c8de6a23 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 2 Jan 2019 18:08:14 +0300 Subject: move world-symbols to file_symbols --- crates/ra_analysis/src/imp.rs | 38 ++---------------------------- crates/ra_analysis/src/lib.rs | 4 +--- crates/ra_analysis/src/symbol_index.rs | 42 +++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 42 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 8071554a7..9ac52b5c3 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -3,7 +3,6 @@ use std::{ sync::Arc, }; -use rayon::prelude::*; use salsa::{Database, ParallelDatabase}; use hir::{ @@ -25,7 +24,7 @@ use crate::{ completion::{CompletionItem, completions}, CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, - symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase, FileSymbol}, + symbol_index::{LibrarySymbolsQuery, FileSymbol}, }; #[derive(Debug, Default)] @@ -149,39 +148,6 @@ impl AnalysisImpl { pub fn file_line_index(&self, file_id: FileId) -> Arc { self.db.file_lines(file_id) } - pub fn world_symbols(&self, query: Query) -> Cancelable> { - /// Need to wrap Snapshot to provide `Clone` impl for `map_with` - struct Snap(salsa::Snapshot); - impl Clone for Snap { - fn clone(&self) -> Snap { - Snap(self.0.snapshot()) - } - } - - let buf: Vec> = if query.libs { - let snap = Snap(self.db.snapshot()); - self.db - .library_roots() - .par_iter() - .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id)) - .collect() - } else { - let mut files = Vec::new(); - for &root in self.db.local_roots().iter() { - let sr = self.db.source_root(root); - files.extend(sr.files.values().map(|&it| it)) - } - - let snap = Snap(self.db.snapshot()); - files - .par_iter() - .map_with(snap, |db, &file_id| db.0.file_symbols(file_id)) - .filter_map(|it| it.ok()) - .collect() - }; - Ok(query.search(&buf)) - } - pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable> { let descr = match source_binder::module_from_position(&*self.db, position)? { None => return Ok(None), @@ -555,7 +521,7 @@ impl AnalysisImpl { let mut query = Query::new(name.to_string()); query.exact(); query.limit(4); - self.world_symbols(query) + crate::symbol_index::world_symbols(&*self.db, query) } } diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 9576453ab..03550832e 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -342,9 +342,7 @@ impl Analysis { ra_editor::folding_ranges(&file) } pub fn symbol_search(&self, query: Query) -> Cancelable> { - let res = self - .imp - .world_symbols(query)? + let res = symbol_index::world_symbols(&*self.imp.db, query)? .into_iter() .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) .collect(); diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index 56a84a850..ddcf3d052 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs @@ -10,12 +10,13 @@ use ra_syntax::{ SyntaxKind::{self, *}, ast::{self, NameOwner, DocCommentsOwner}, }; -use ra_db::{SyntaxDatabase, SourceRootId}; +use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase}; +use salsa::ParallelDatabase; use rayon::prelude::*; use crate::{ - Cancelable, - FileId, Query, + Cancelable, FileId, Query, + db::RootDatabase, }; salsa::query_group! { @@ -36,6 +37,41 @@ fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable Cancelable> { + /// Need to wrap Snapshot to provide `Clone` impl for `map_with` + struct Snap(salsa::Snapshot); + impl Clone for Snap { + fn clone(&self) -> Snap { + Snap(self.0.snapshot()) + } + } + + let buf: Vec> = if query.libs { + let snap = Snap(db.snapshot()); + db.library_roots() + .par_iter() + .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id)) + .collect() + } else { + let mut files = Vec::new(); + for &root in db.local_roots().iter() { + let sr = db.source_root(root); + files.extend(sr.files.values().map(|&it| it)) + } + + let snap = Snap(db.snapshot()); + files + .par_iter() + .map_with(snap, |db, &file_id| db.0.file_symbols(file_id)) + .filter_map(|it| it.ok()) + .collect() + }; + Ok(query.search(&buf)) +} + #[derive(Default, Debug)] pub(crate) struct SymbolIndex { symbols: Vec<(FileId, FileSymbol)>, -- cgit v1.2.3