rust-analyzer/crates/ra_ide_api/src/db.rs

116 lines
4.1 KiB
Rust
Raw Normal View History

2019-01-24 09:41:08 +00:00
use std::sync::Arc;
2019-01-08 19:33:36 +00:00
2019-01-17 11:11:00 +00:00
use ra_db::{
2019-01-24 09:41:08 +00:00
BaseDatabase, FileId, Canceled,
2019-01-17 11:11:00 +00:00
salsa::{self, Database},
};
2019-01-08 19:33:36 +00:00
use crate::{symbol_index, LineIndex};
#[derive(Debug)]
pub(crate) struct RootDatabase {
runtime: salsa::Runtime<RootDatabase>,
2019-01-24 09:41:08 +00:00
interner: Arc<hir::HirInterner>,
2019-01-08 19:33:36 +00:00
}
impl salsa::Database for RootDatabase {
fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
&self.runtime
}
2019-01-10 09:20:32 +00:00
fn on_propagated_panic(&self) -> ! {
Canceled::throw()
}
2019-01-08 19:33:36 +00:00
}
impl Default for RootDatabase {
fn default() -> RootDatabase {
let mut db = RootDatabase {
runtime: salsa::Runtime::default(),
2019-01-24 09:41:08 +00:00
interner: Default::default(),
2019-01-08 19:33:36 +00:00
};
db.query_mut(ra_db::CrateGraphQuery)
.set((), Default::default());
db.query_mut(ra_db::LocalRootsQuery)
.set((), Default::default());
db.query_mut(ra_db::LibraryRootsQuery)
.set((), Default::default());
db
}
}
impl salsa::ParallelDatabase for RootDatabase {
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
salsa::Snapshot::new(RootDatabase {
runtime: self.runtime.snapshot(self),
2019-01-24 09:41:08 +00:00
interner: Arc::clone(&self.interner),
2019-01-08 19:33:36 +00:00
})
}
}
impl BaseDatabase for RootDatabase {}
2019-01-24 09:41:08 +00:00
impl AsRef<hir::HirInterner> for RootDatabase {
fn as_ref(&self) -> &hir::HirInterner {
&self.interner
2019-01-08 19:33:36 +00:00
}
}
2019-01-17 11:11:00 +00:00
#[salsa::query_group]
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
2019-01-08 19:33:36 +00:00
}
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;
2019-01-08 19:33:36 +00:00
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;
2019-01-17 11:11:00 +00:00
fn expand_macro_invocation() for hir::db::ExpandMacroInvocationQuery;
2019-01-08 19:33:36 +00:00
fn module_tree() for hir::db::ModuleTreeQuery;
fn fn_scopes() for hir::db::FnScopesQuery;
2019-01-17 11:11:00 +00:00
fn file_items() for hir::db::FileItemsQuery;
2019-01-08 19:33:36 +00:00
fn file_item() for hir::db::FileItemQuery;
2019-01-18 13:36:56 +00:00
fn lower_module() for hir::db::LowerModuleQuery;
fn lower_module_module() for hir::db::LowerModuleModuleQuery;
fn lower_module_source_map() for hir::db::LowerModuleSourceMapQuery;
2019-01-08 19:33:36 +00:00
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;
2019-01-08 19:33:36 +00:00
fn body_hir() for hir::db::BodyHirQuery;
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
fn fn_signature() for hir::db::FnSignatureQuery;
2019-01-19 17:58:04 +00:00
fn generic_params() for hir::db::GenericParamsQuery;
2019-01-08 19:33:36 +00:00
}
}
}