mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
index all local crates
This commit is contained in:
parent
51fec4ef84
commit
e6465e7e2a
6 changed files with 37 additions and 33 deletions
|
@ -30,11 +30,11 @@ impl Default for RootDatabase {
|
||||||
runtime: salsa::Runtime::default(),
|
runtime: salsa::Runtime::default(),
|
||||||
id_maps: Default::default(),
|
id_maps: Default::default(),
|
||||||
};
|
};
|
||||||
db.query_mut(ra_db::SourceRootQuery)
|
|
||||||
.set(ra_db::WORKSPACE, Default::default());
|
|
||||||
db.query_mut(ra_db::CrateGraphQuery)
|
db.query_mut(ra_db::CrateGraphQuery)
|
||||||
.set((), Default::default());
|
.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());
|
.set((), Default::default());
|
||||||
db
|
db
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ salsa::database_storage! {
|
||||||
fn file_relative_path() for ra_db::FileRelativePathQuery;
|
fn file_relative_path() for ra_db::FileRelativePathQuery;
|
||||||
fn file_source_root() for ra_db::FileSourceRootQuery;
|
fn file_source_root() for ra_db::FileSourceRootQuery;
|
||||||
fn source_root() for ra_db::SourceRootQuery;
|
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;
|
fn crate_graph() for ra_db::CrateGraphQuery;
|
||||||
}
|
}
|
||||||
impl ra_db::SyntaxDatabase {
|
impl ra_db::SyntaxDatabase {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use ra_syntax::{
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
SyntaxNodeRef, TextRange, TextUnit,
|
SyntaxNodeRef, TextRange, TextUnit,
|
||||||
};
|
};
|
||||||
use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase};
|
use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use salsa::{Database, ParallelDatabase};
|
use salsa::{Database, ParallelDatabase};
|
||||||
use hir::{
|
use hir::{
|
||||||
|
@ -56,7 +56,7 @@ impl AnalysisHostImpl {
|
||||||
self.db.query_mut(ra_db::FileTextQuery).set(file_id, text)
|
self.db.query_mut(ra_db::FileTextQuery).set(file_id, text)
|
||||||
}
|
}
|
||||||
if !change.libraries_added.is_empty() {
|
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 {
|
for library in change.libraries_added {
|
||||||
libraries.push(library.root_id);
|
libraries.push(library.root_id);
|
||||||
self.db
|
self.db
|
||||||
|
@ -65,7 +65,7 @@ impl AnalysisHostImpl {
|
||||||
self.apply_root_change(library.root_id, library.root_change);
|
self.apply_root_change(library.root_id, library.root_change);
|
||||||
}
|
}
|
||||||
self.db
|
self.db
|
||||||
.query_mut(ra_db::LibrariesQuery)
|
.query_mut(ra_db::LibraryRootsQuery)
|
||||||
.set((), Arc::new(libraries));
|
.set((), Arc::new(libraries));
|
||||||
}
|
}
|
||||||
if let Some(crate_graph) = change.crate_graph {
|
if let Some(crate_graph) = change.crate_graph {
|
||||||
|
@ -142,27 +142,26 @@ impl AnalysisImpl {
|
||||||
self.db.file_lines(file_id)
|
self.db.file_lines(file_id)
|
||||||
}
|
}
|
||||||
pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
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 buf: Vec<Arc<SymbolIndex>> = if query.libs {
|
||||||
|
let snap = Snap(self.db.snapshot());
|
||||||
self.db
|
self.db
|
||||||
.libraries()
|
.library_roots()
|
||||||
.iter()
|
.par_iter()
|
||||||
.map(|&lib_id| self.db.library_symbols(lib_id))
|
.map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
let files: Vec<FileId> = self
|
let mut files = Vec::new();
|
||||||
.db
|
for &root in self.db.local_roots().iter() {
|
||||||
.source_root(WORKSPACE)
|
let sr = self.db.source_root(root);
|
||||||
.files
|
files.extend(sr.files.values().map(|&it| it))
|
||||||
.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 snap = Snap(self.db.snapshot());
|
let snap = Snap(self.db.snapshot());
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub use hir::FnSignatureInfo;
|
||||||
|
|
||||||
pub use ra_db::{
|
pub use ra_db::{
|
||||||
Canceled, Cancelable, FilePosition,
|
Canceled, Cancelable, FilePosition,
|
||||||
CrateGraph, CrateId, SourceRootId, FileId, WORKSPACE
|
CrateGraph, CrateId, SourceRootId, FileId
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -4,7 +4,7 @@ use relative_path::{RelativePathBuf};
|
||||||
use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
|
use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
|
||||||
use ra_db::mock::FileMap;
|
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
|
/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
|
||||||
/// from a set of in-memory files.
|
/// from a set of in-memory files.
|
||||||
|
@ -78,12 +78,14 @@ impl MockAnalysis {
|
||||||
pub fn analysis_host(self) -> AnalysisHost {
|
pub fn analysis_host(self) -> AnalysisHost {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let mut file_map = FileMap::default();
|
let mut file_map = FileMap::default();
|
||||||
|
let source_root = SourceRootId(0);
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
|
change.add_root(source_root);
|
||||||
for (path, contents) in self.files.into_iter() {
|
for (path, contents) in self.files.into_iter() {
|
||||||
assert!(path.starts_with('/'));
|
assert!(path.starts_with('/'));
|
||||||
let path = RelativePathBuf::from_path(&path[1..]).unwrap();
|
let path = RelativePathBuf::from_path(&path[1..]).unwrap();
|
||||||
let file_id = file_map.add(path.clone());
|
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));
|
// change.set_file_resolver(Arc::new(file_map));
|
||||||
host.apply_change(change);
|
host.apply_change(change);
|
||||||
|
|
|
@ -8,8 +8,6 @@ use salsa;
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct SourceRootId(pub u32);
|
pub struct SourceRootId(pub u32);
|
||||||
|
|
||||||
pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct FileId(pub u32);
|
pub struct FileId(pub u32);
|
||||||
|
|
||||||
|
@ -102,8 +100,12 @@ salsa::query_group! {
|
||||||
type SourceRootQuery;
|
type SourceRootQuery;
|
||||||
storage input;
|
storage input;
|
||||||
}
|
}
|
||||||
fn libraries() -> Arc<Vec<SourceRootId>> {
|
fn local_roots() -> Arc<Vec<SourceRootId>> {
|
||||||
type LibrariesQuery;
|
type LocalRootsQuery;
|
||||||
|
storage input;
|
||||||
|
}
|
||||||
|
fn library_roots() -> Arc<Vec<SourceRootId>> {
|
||||||
|
type LibraryRootsQuery;
|
||||||
storage input;
|
storage input;
|
||||||
}
|
}
|
||||||
fn crate_graph() -> Arc<CrateGraph> {
|
fn crate_graph() -> Arc<CrateGraph> {
|
||||||
|
|
|
@ -24,8 +24,8 @@ impl std::error::Error for Canceled {}
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
syntax_ptr::LocalSyntaxPtr,
|
syntax_ptr::LocalSyntaxPtr,
|
||||||
input::{
|
input::{
|
||||||
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE,
|
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph,
|
||||||
FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery,
|
FileTextQuery, FileSourceRootQuery, SourceRootQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery,
|
||||||
FileRelativePathQuery
|
FileRelativePathQuery
|
||||||
},
|
},
|
||||||
loc2id::{LocationIntener, NumericId},
|
loc2id::{LocationIntener, NumericId},
|
||||||
|
|
Loading…
Reference in a new issue