From e6465e7e2a7e136edd652d5f4c93b961dd652cbc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 16:13:16 +0300 Subject: [PATCH] index all local crates --- crates/ra_analysis/src/db.rs | 9 +++--- crates/ra_analysis/src/imp.rs | 39 ++++++++++++------------- crates/ra_analysis/src/lib.rs | 2 +- crates/ra_analysis/src/mock_analysis.rs | 6 ++-- crates/ra_db/src/input.rs | 10 ++++--- crates/ra_db/src/lib.rs | 4 +-- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index b79baf0370..3d0f13f341 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -30,11 +30,11 @@ impl Default for RootDatabase { runtime: salsa::Runtime::default(), id_maps: Default::default(), }; - db.query_mut(ra_db::SourceRootQuery) - .set(ra_db::WORKSPACE, Default::default()); db.query_mut(ra_db::CrateGraphQuery) .set((), Default::default()); - db.query_mut(ra_db::LibrariesQuery) + db.query_mut(ra_db::LocalRootsQuery) + .set((), Default::default()); + db.query_mut(ra_db::LibraryRootsQuery) .set((), Default::default()); db } @@ -64,7 +64,8 @@ salsa::database_storage! { fn file_relative_path() for ra_db::FileRelativePathQuery; fn file_source_root() for ra_db::FileSourceRootQuery; fn source_root() for ra_db::SourceRootQuery; - fn libraries() for ra_db::LibrariesQuery; + fn local_roots() for ra_db::LocalRootsQuery; + fn library_roots() for ra_db::LibraryRootsQuery; fn crate_graph() for ra_db::CrateGraphQuery; } impl ra_db::SyntaxDatabase { diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 54f38b2855..46169d8631 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -10,7 +10,7 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, }; -use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; +use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; use rayon::prelude::*; use salsa::{Database, ParallelDatabase}; use hir::{ @@ -56,7 +56,7 @@ impl AnalysisHostImpl { self.db.query_mut(ra_db::FileTextQuery).set(file_id, text) } if !change.libraries_added.is_empty() { - let mut libraries = Vec::clone(&self.db.libraries()); + let mut libraries = Vec::clone(&self.db.library_roots()); for library in change.libraries_added { libraries.push(library.root_id); self.db @@ -65,7 +65,7 @@ impl AnalysisHostImpl { self.apply_root_change(library.root_id, library.root_change); } self.db - .query_mut(ra_db::LibrariesQuery) + .query_mut(ra_db::LibraryRootsQuery) .set((), Arc::new(libraries)); } if let Some(crate_graph) = change.crate_graph { @@ -142,27 +142,26 @@ impl AnalysisImpl { 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 - .libraries() - .iter() - .map(|&lib_id| self.db.library_symbols(lib_id)) + .library_roots() + .par_iter() + .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id)) .collect() } else { - let files: Vec = self - .db - .source_root(WORKSPACE) - .files - .values() - .map(|&it| it) - .collect(); - - /// 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 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()); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 300dfc5dd6..0db3c34794 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -39,7 +39,7 @@ pub use hir::FnSignatureInfo; pub use ra_db::{ Canceled, Cancelable, FilePosition, - CrateGraph, CrateId, SourceRootId, FileId, WORKSPACE + CrateGraph, CrateId, SourceRootId, FileId }; #[derive(Default)] diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 691af4a48c..0c042e672d 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -4,7 +4,7 @@ use relative_path::{RelativePathBuf}; use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; use ra_db::mock::FileMap; -use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, WORKSPACE}; +use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, SourceRootId}; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -78,12 +78,14 @@ impl MockAnalysis { pub fn analysis_host(self) -> AnalysisHost { let mut host = AnalysisHost::default(); let mut file_map = FileMap::default(); + let source_root = SourceRootId(0); let mut change = AnalysisChange::new(); + change.add_root(source_root); for (path, contents) in self.files.into_iter() { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let file_id = file_map.add(path.clone()); - change.add_file(WORKSPACE, file_id, path, Arc::new(contents)); + change.add_file(source_root, file_id, path, Arc::new(contents)); } // change.set_file_resolver(Arc::new(file_map)); host.apply_change(change); diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 51daa8e860..cccf37cc28 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -8,8 +8,6 @@ use salsa; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct SourceRootId(pub u32); -pub const WORKSPACE: SourceRootId = SourceRootId(0); - #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FileId(pub u32); @@ -102,8 +100,12 @@ salsa::query_group! { type SourceRootQuery; storage input; } - fn libraries() -> Arc> { - type LibrariesQuery; + fn local_roots() -> Arc> { + type LocalRootsQuery; + storage input; + } + fn library_roots() -> Arc> { + type LibraryRootsQuery; storage input; } fn crate_graph() -> Arc { diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index eeb305b1b3..65fa3cbfa4 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -24,8 +24,8 @@ impl std::error::Error for Canceled {} pub use crate::{ syntax_ptr::LocalSyntaxPtr, input::{ - FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE, - FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery, + FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, + FileTextQuery, FileSourceRootQuery, SourceRootQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery, FileRelativePathQuery }, loc2id::{LocationIntener, NumericId},