rust/crates/ra_analysis/src/db.rs

90 lines
2.8 KiB
Rust
Raw Normal View History

2018-10-31 15:41:43 -05:00
use std::sync::Arc;
2018-11-04 05:09:21 -06:00
use salsa::{self, Database};
use ra_db::{LocationIntener, BaseDatabase};
2018-12-04 14:44:00 -06:00
use hir::{self, DefId, DefLoc};
2018-10-20 14:29:26 -05:00
use crate::{
2018-11-27 17:22:25 -06:00
symbol_index,
};
2018-09-13 14:58:36 -05:00
2018-11-04 05:09:21 -06:00
#[derive(Debug)]
2018-10-07 05:18:25 -05:00
pub(crate) struct RootDatabase {
2018-10-20 10:43:02 -05:00
runtime: salsa::Runtime<RootDatabase>,
2018-11-27 17:49:28 -06:00
id_maps: Arc<IdMaps>,
2018-09-13 14:58:36 -05:00
}
2018-11-27 18:31:50 -06:00
#[derive(Debug, Default)]
struct IdMaps {
defs: LocationIntener<DefLoc, DefId>,
}
2018-10-07 05:18:25 -05:00
impl salsa::Database for RootDatabase {
2018-10-20 10:43:02 -05:00
fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
2018-10-07 05:18:25 -05:00
&self.runtime
}
2018-09-13 14:58:36 -05:00
}
2018-11-04 05:09:21 -06:00
impl Default for RootDatabase {
fn default() -> RootDatabase {
let mut db = RootDatabase {
2018-11-18 07:21:23 -06:00
runtime: salsa::Runtime::default(),
2018-11-27 17:49:28 -06:00
id_maps: Default::default(),
2018-11-04 05:09:21 -06:00
};
db.query_mut(ra_db::SourceRootQuery)
.set(ra_db::WORKSPACE, Default::default());
db.query_mut(ra_db::CrateGraphQuery)
2018-11-04 05:09:21 -06:00
.set((), Default::default());
db.query_mut(ra_db::LibrariesQuery)
2018-11-04 05:09:21 -06:00
.set((), Default::default());
db
}
}
2018-10-15 14:29:24 -05:00
impl salsa::ParallelDatabase for RootDatabase {
2018-11-01 07:29:23 -05:00
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
salsa::Snapshot::new(RootDatabase {
runtime: self.runtime.snapshot(self),
2018-11-18 07:21:23 -06:00
id_maps: self.id_maps.clone(),
2018-11-01 07:29:23 -05:00
})
2018-10-15 14:29:24 -05:00
}
}
impl BaseDatabase for RootDatabase {}
2018-11-18 07:21:23 -06:00
2018-11-27 17:49:28 -06:00
impl AsRef<LocationIntener<DefLoc, DefId>> for RootDatabase {
fn as_ref(&self) -> &LocationIntener<DefLoc, DefId> {
&self.id_maps.defs
}
}
2018-10-07 05:18:25 -05:00
salsa::database_storage! {
pub(crate) struct RootDatabaseStorage for RootDatabase {
impl ra_db::FilesDatabase {
fn file_text() for ra_db::FileTextQuery;
2018-12-19 01:26:24 -06:00
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 crate_graph() for ra_db::CrateGraphQuery;
2018-10-07 05:18:25 -05:00
}
impl ra_db::SyntaxDatabase {
fn source_file() for ra_db::SourceFileQuery;
fn file_lines() for ra_db::FileLinesQuery;
2018-11-27 17:22:25 -06:00
}
impl symbol_index::SymbolsDatabase {
fn file_symbols() for symbol_index::FileSymbolsQuery;
fn library_symbols() for symbol_index::LibrarySymbolsQuery;
2018-10-07 05:18:25 -05:00
}
2018-11-27 14:03:08 -06:00
impl hir::db::HirDatabase {
fn module_tree() for hir::db::ModuleTreeQuery;
fn fn_scopes() for hir::db::FnScopesQuery;
2018-11-27 17:22:25 -06:00
fn file_items() for hir::db::SourceFileItemsQuery;
fn file_item() for hir::db::FileItemQuery;
fn input_module_items() for hir::db::InputModuleItemsQuery;
fn item_map() for hir::db::ItemMapQuery;
fn fn_syntax() for hir::db::FnSyntaxQuery;
fn submodules() for hir::db::SubmodulesQuery;
}
2018-10-07 05:18:25 -05:00
}
2018-09-13 14:58:36 -05:00
}