mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Merge #639
639: Update salsa r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
021e691997
11 changed files with 108 additions and 212 deletions
|
@ -7,6 +7,13 @@ use ra_db::{
|
|||
|
||||
use crate::{symbol_index, LineIndex};
|
||||
|
||||
#[salsa::database(
|
||||
ra_db::FilesDatabase,
|
||||
ra_db::SyntaxDatabase,
|
||||
LineIndexDatabase,
|
||||
symbol_index::SymbolsDatabase,
|
||||
hir::db::HirDatabase
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct RootDatabase {
|
||||
runtime: salsa::Runtime<RootDatabase>,
|
||||
|
@ -64,52 +71,3 @@ fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex>
|
|||
let text = db.file_text(file_id);
|
||||
Arc::new(LineIndex::new(&*text))
|
||||
}
|
||||
|
||||
salsa::database_storage! {
|
||||
pub(crate) struct RootDatabaseStorage for RootDatabase {
|
||||
impl ra_db::FilesDatabase {
|
||||
fn file_text() for ra_db::FileTextQuery;
|
||||
fn file_relative_path() for ra_db::FileRelativePathQuery;
|
||||
fn file_source_root() for ra_db::FileSourceRootQuery;
|
||||
fn source_root() for ra_db::SourceRootQuery;
|
||||
fn source_root_crates() for ra_db::SourceRootCratesQuery;
|
||||
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 {
|
||||
fn source_file() for ra_db::SourceFileQuery;
|
||||
}
|
||||
impl LineIndexDatabase {
|
||||
fn line_index() for LineIndexQuery;
|
||||
}
|
||||
impl symbol_index::SymbolsDatabase {
|
||||
fn file_symbols() for symbol_index::FileSymbolsQuery;
|
||||
fn library_symbols() for symbol_index::LibrarySymbolsQuery;
|
||||
}
|
||||
impl hir::db::HirDatabase {
|
||||
fn hir_source_file() for hir::db::HirSourceFileQuery;
|
||||
fn expand_macro_invocation() for hir::db::ExpandMacroInvocationQuery;
|
||||
fn module_tree() for hir::db::ModuleTreeQuery;
|
||||
fn fn_scopes() for hir::db::FnScopesQuery;
|
||||
fn file_items() for hir::db::FileItemsQuery;
|
||||
fn file_item() for hir::db::FileItemQuery;
|
||||
fn lower_module() for hir::db::LowerModuleQuery;
|
||||
fn lower_module_module() for hir::db::LowerModuleModuleQuery;
|
||||
fn lower_module_source_map() for hir::db::LowerModuleSourceMapQuery;
|
||||
fn item_map() for hir::db::ItemMapQuery;
|
||||
fn submodules() for hir::db::SubmodulesQuery;
|
||||
fn infer() for hir::db::InferQuery;
|
||||
fn type_for_def() for hir::db::TypeForDefQuery;
|
||||
fn type_for_field() for hir::db::TypeForFieldQuery;
|
||||
fn struct_data() for hir::db::StructDataQuery;
|
||||
fn enum_data() for hir::db::EnumDataQuery;
|
||||
fn impls_in_module() for hir::db::ImplsInModuleQuery;
|
||||
fn impls_in_crate() for hir::db::ImplsInCrateQuery;
|
||||
fn body_hir() for hir::db::BodyHirQuery;
|
||||
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
|
||||
fn fn_signature() for hir::db::FnSignatureQuery;
|
||||
fn generic_params() for hir::db::GenericParamsQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use hir::{
|
|||
};
|
||||
use ra_db::{
|
||||
FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase,
|
||||
salsa::{self, Database},
|
||||
salsa::Database,
|
||||
};
|
||||
use ra_ide_api_light::{self, assists, LocalEdit, Severity};
|
||||
use ra_syntax::{
|
||||
|
@ -18,7 +18,7 @@ use crate::{
|
|||
AnalysisChange,
|
||||
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
|
||||
Query, RootChange, SourceChange, SourceFileEdit,
|
||||
symbol_index::{FileSymbol, LibrarySymbolsQuery},
|
||||
symbol_index::{FileSymbol, SymbolsDatabase},
|
||||
};
|
||||
|
||||
impl db::RootDatabase {
|
||||
|
@ -28,59 +28,48 @@ impl db::RootDatabase {
|
|||
if !change.new_roots.is_empty() {
|
||||
let mut local_roots = Vec::clone(&self.local_roots());
|
||||
for (root_id, is_local) in change.new_roots {
|
||||
self.query_mut(ra_db::SourceRootQuery)
|
||||
.set(root_id, Default::default());
|
||||
self.set_source_root(root_id, Default::default());
|
||||
if is_local {
|
||||
local_roots.push(root_id);
|
||||
}
|
||||
}
|
||||
self.query_mut(ra_db::LocalRootsQuery)
|
||||
.set((), Arc::new(local_roots));
|
||||
self.set_local_roots(Arc::new(local_roots));
|
||||
}
|
||||
|
||||
for (root_id, root_change) in change.roots_changed {
|
||||
self.apply_root_change(root_id, root_change);
|
||||
}
|
||||
for (file_id, text) in change.files_changed {
|
||||
self.query_mut(ra_db::FileTextQuery).set(file_id, text)
|
||||
self.set_file_text(file_id, text)
|
||||
}
|
||||
if !change.libraries_added.is_empty() {
|
||||
let mut libraries = Vec::clone(&self.library_roots());
|
||||
for library in change.libraries_added {
|
||||
libraries.push(library.root_id);
|
||||
self.query_mut(ra_db::SourceRootQuery)
|
||||
.set(library.root_id, Default::default());
|
||||
self.query_mut(LibrarySymbolsQuery)
|
||||
.set_constant(library.root_id, Arc::new(library.symbol_index));
|
||||
self.set_source_root(library.root_id, Default::default());
|
||||
self.set_constant_library_symbols(library.root_id, Arc::new(library.symbol_index));
|
||||
self.apply_root_change(library.root_id, library.root_change);
|
||||
}
|
||||
self.query_mut(ra_db::LibraryRootsQuery)
|
||||
.set((), Arc::new(libraries));
|
||||
self.set_library_roots(Arc::new(libraries));
|
||||
}
|
||||
if let Some(crate_graph) = change.crate_graph {
|
||||
self.query_mut(ra_db::CrateGraphQuery)
|
||||
.set((), Arc::new(crate_graph))
|
||||
self.set_crate_graph(Arc::new(crate_graph))
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
|
||||
let mut source_root = SourceRoot::clone(&self.source_root(root_id));
|
||||
for add_file in root_change.added {
|
||||
self.query_mut(ra_db::FileTextQuery)
|
||||
.set(add_file.file_id, add_file.text);
|
||||
self.query_mut(ra_db::FileRelativePathQuery)
|
||||
.set(add_file.file_id, add_file.path.clone());
|
||||
self.query_mut(ra_db::FileSourceRootQuery)
|
||||
.set(add_file.file_id, root_id);
|
||||
self.set_file_text(add_file.file_id, add_file.text);
|
||||
self.set_file_relative_path(add_file.file_id, add_file.path.clone());
|
||||
self.set_file_source_root(add_file.file_id, root_id);
|
||||
source_root.files.insert(add_file.path, add_file.file_id);
|
||||
}
|
||||
for remove_file in root_change.removed {
|
||||
self.query_mut(ra_db::FileTextQuery)
|
||||
.set(remove_file.file_id, Default::default());
|
||||
self.set_file_text(remove_file.file_id, Default::default());
|
||||
source_root.files.remove(&remove_file.path);
|
||||
}
|
||||
self.query_mut(ra_db::SourceRootQuery)
|
||||
.set(root_id, Arc::new(source_root));
|
||||
self.set_source_root(root_id, Arc::new(source_root));
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
|
|
|
@ -6,7 +6,7 @@ use ra_db::{
|
|||
use crate::db::RootDatabase;
|
||||
|
||||
pub(crate) fn status(db: &RootDatabase) -> String {
|
||||
let n_parsed_files = db.query(SourceFileQuery).keys::<Vec<_>>().len();
|
||||
let n_parsed_files = db.query(SourceFileQuery).entries::<Vec<_>>().len();
|
||||
let n_defs = {
|
||||
let interner: &hir::HirInterner = db.as_ref();
|
||||
interner.len()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue