index all local crates

This commit is contained in:
Aleksey Kladov 2018-12-19 16:13:16 +03:00
parent 51fec4ef84
commit e6465e7e2a
6 changed files with 37 additions and 33 deletions

View file

@ -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 {

View file

@ -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<Vec<(FileId, FileSymbol)>> {
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
struct Snap(salsa::Snapshot<db::RootDatabase>);
impl Clone for Snap {
fn clone(&self) -> Snap {
Snap(self.0.snapshot())
}
}
let buf: Vec<Arc<SymbolIndex>> = 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<FileId> = 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<db::RootDatabase>);
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());

View file

@ -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)]

View file

@ -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);

View file

@ -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<Vec<SourceRootId>> {
type LibrariesQuery;
fn local_roots() -> Arc<Vec<SourceRootId>> {
type LocalRootsQuery;
storage input;
}
fn library_roots() -> Arc<Vec<SourceRootId>> {
type LibraryRootsQuery;
storage input;
}
fn crate_graph() -> Arc<CrateGraph> {

View file

@ -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},