aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/test_db.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-13 15:26:29 +0100
committerAleksey Kladov <[email protected]>2020-08-13 15:29:33 +0100
commitb7aa4898e0841ab8199643f89a0caa967b698ca8 (patch)
treeafb23bbff9fa1b39afc51f58b0e0175d55e3596c /crates/hir_expand/src/test_db.rs
parented20a857f485a471369cd99b843af19a4d875ad0 (diff)
Rename ra_hir_expand -> hir_expand
Diffstat (limited to 'crates/hir_expand/src/test_db.rs')
-rw-r--r--crates/hir_expand/src/test_db.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/hir_expand/src/test_db.rs b/crates/hir_expand/src/test_db.rs
new file mode 100644
index 000000000..86a5d867e
--- /dev/null
+++ b/crates/hir_expand/src/test_db.rs
@@ -0,0 +1,49 @@
1//! Database used for testing `hir_expand`.
2
3use std::{
4 fmt, panic,
5 sync::{Arc, Mutex},
6};
7
8use base_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate};
9use rustc_hash::FxHashSet;
10
11#[salsa::database(
12 base_db::SourceDatabaseExtStorage,
13 base_db::SourceDatabaseStorage,
14 crate::db::AstDatabaseStorage
15)]
16#[derive(Default)]
17pub struct TestDB {
18 storage: salsa::Storage<TestDB>,
19 events: Mutex<Option<Vec<salsa::Event>>>,
20}
21
22impl fmt::Debug for TestDB {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 f.debug_struct("TestDB").finish()
25 }
26}
27
28impl salsa::Database for TestDB {
29 fn salsa_event(&self, event: salsa::Event) {
30 let mut events = self.events.lock().unwrap();
31 if let Some(events) = &mut *events {
32 events.push(event);
33 }
34 }
35}
36
37impl panic::RefUnwindSafe for TestDB {}
38
39impl FileLoader for TestDB {
40 fn file_text(&self, file_id: FileId) -> Arc<String> {
41 FileLoaderDelegate(self).file_text(file_id)
42 }
43 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
44 FileLoaderDelegate(self).resolve_path(anchor, path)
45 }
46 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
47 FileLoaderDelegate(self).relevant_crates(file_id)
48 }
49}