2019-11-22 17:11:33 +00:00
|
|
|
//! Database used for testing `hir_expand`.
|
|
|
|
|
|
|
|
use std::{
|
2020-07-07 08:14:48 +00:00
|
|
|
fmt, panic,
|
2019-11-22 17:11:33 +00:00
|
|
|
sync::{Arc, Mutex},
|
|
|
|
};
|
|
|
|
|
2020-12-09 16:01:15 +00:00
|
|
|
use base_db::{salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate};
|
2020-06-11 09:30:06 +00:00
|
|
|
use rustc_hash::FxHashSet;
|
2019-11-22 17:11:33 +00:00
|
|
|
|
|
|
|
#[salsa::database(
|
2020-08-13 14:25:38 +00:00
|
|
|
base_db::SourceDatabaseExtStorage,
|
|
|
|
base_db::SourceDatabaseStorage,
|
2019-11-22 17:11:33 +00:00
|
|
|
crate::db::AstDatabaseStorage
|
|
|
|
)]
|
2020-07-07 08:14:48 +00:00
|
|
|
#[derive(Default)]
|
2020-11-02 15:31:38 +00:00
|
|
|
pub(crate) struct TestDB {
|
2020-07-07 08:14:48 +00:00
|
|
|
storage: salsa::Storage<TestDB>,
|
|
|
|
events: Mutex<Option<Vec<salsa::Event>>>,
|
2019-11-22 17:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:14:48 +00:00
|
|
|
impl fmt::Debug for TestDB {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_struct("TestDB").finish()
|
2019-11-26 08:29:20 +00:00
|
|
|
}
|
2020-07-07 08:14:48 +00:00
|
|
|
}
|
2019-11-26 08:29:20 +00:00
|
|
|
|
2020-07-07 08:14:48 +00:00
|
|
|
impl salsa::Database for TestDB {
|
|
|
|
fn salsa_event(&self, event: salsa::Event) {
|
2019-11-22 17:11:33 +00:00
|
|
|
let mut events = self.events.lock().unwrap();
|
|
|
|
if let Some(events) = &mut *events {
|
2020-07-07 08:14:48 +00:00
|
|
|
events.push(event);
|
2019-11-22 17:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl panic::RefUnwindSafe for TestDB {}
|
|
|
|
|
|
|
|
impl FileLoader for TestDB {
|
|
|
|
fn file_text(&self, file_id: FileId) -> Arc<String> {
|
|
|
|
FileLoaderDelegate(self).file_text(file_id)
|
|
|
|
}
|
2020-12-09 16:01:15 +00:00
|
|
|
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
|
|
|
|
FileLoaderDelegate(self).resolve_path(path)
|
2019-11-22 17:11:33 +00:00
|
|
|
}
|
2020-06-11 09:30:06 +00:00
|
|
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
2019-11-22 17:11:33 +00:00
|
|
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
|
|
|
}
|
|
|
|
}
|