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

70 lines
1.8 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-26 08:20:30 +00:00
CheckCanceled, FileId, Canceled, SourceDatabase,
2019-01-26 08:17:05 +00:00
salsa,
2019-01-17 11:11:00 +00:00
};
2019-01-08 19:33:36 +00:00
2019-01-26 08:17:05 +00:00
use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
2019-01-08 19:33:36 +00:00
2019-01-25 12:16:50 +00:00
#[salsa::database(
2019-01-26 08:20:30 +00:00
ra_db::SourceDatabaseStorage,
2019-01-25 20:27:16 +00:00
LineIndexDatabaseStorage,
symbol_index::SymbolsDatabaseStorage,
hir::db::HirDatabaseStorage
2019-01-25 12:16:50 +00:00
)]
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
};
2019-01-26 08:17:05 +00:00
db.set_crate_graph(Default::default());
db.set_local_roots(Default::default());
db.set_library_roots(Default::default());
2019-01-08 19:33:36 +00:00
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 CheckCanceled for RootDatabase {}
2019-01-08 19:33:36 +00:00
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-25 20:27:16 +00:00
#[salsa::query_group(LineIndexDatabaseStorage)]
2019-01-26 08:20:30 +00:00
pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
2019-01-17 11:11:00 +00:00
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
2019-01-08 19:33:36 +00:00
}
2019-01-26 08:20:30 +00:00
fn line_index(db: &impl ra_db::SourceDatabase, file_id: FileId) -> Arc<LineIndex> {
2019-01-08 19:33:36 +00:00
let text = db.file_text(file_id);
Arc::new(LineIndex::new(&*text))
}