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};
|
|
|
|
|
2019-01-25 12:16:50 +00:00
|
|
|
#[salsa::database(
|
|
|
|
ra_db::FilesDatabase,
|
|
|
|
ra_db::SyntaxDatabase,
|
|
|
|
LineIndexDatabase,
|
|
|
|
symbol_index::SymbolsDatabase,
|
|
|
|
hir::db::HirDatabase
|
|
|
|
)]
|
2019-01-08 19:33:36 +00:00
|
|
|
#[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))
|
|
|
|
}
|