diff options
Diffstat (limited to 'crates/ra_hir_def/src/test_db.rs')
-rw-r--r-- | crates/ra_hir_def/src/test_db.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs new file mode 100644 index 000000000..67714c68e --- /dev/null +++ b/crates/ra_hir_def/src/test_db.rs | |||
@@ -0,0 +1,40 @@ | |||
1 | use std::{panic, sync::Arc}; | ||
2 | |||
3 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; | ||
4 | use relative_path::RelativePath; | ||
5 | |||
6 | #[salsa::database( | ||
7 | ra_db::SourceDatabaseExtStorage, | ||
8 | ra_db::SourceDatabaseStorage, | ||
9 | hir_expand::db::AstDatabaseStorage, | ||
10 | crate::db::InternDatabaseStorage, | ||
11 | crate::db::DefDatabase2Storage | ||
12 | )] | ||
13 | #[derive(Debug, Default)] | ||
14 | pub struct TestDB { | ||
15 | runtime: salsa::Runtime<TestDB>, | ||
16 | } | ||
17 | |||
18 | impl salsa::Database for TestDB { | ||
19 | fn salsa_runtime(&self) -> &salsa::Runtime<Self> { | ||
20 | &self.runtime | ||
21 | } | ||
22 | } | ||
23 | |||
24 | impl panic::RefUnwindSafe for TestDB {} | ||
25 | |||
26 | impl FileLoader for TestDB { | ||
27 | fn file_text(&self, file_id: FileId) -> Arc<String> { | ||
28 | FileLoaderDelegate(self).file_text(file_id) | ||
29 | } | ||
30 | fn resolve_relative_path( | ||
31 | &self, | ||
32 | anchor: FileId, | ||
33 | relative_path: &RelativePath, | ||
34 | ) -> Option<FileId> { | ||
35 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
36 | } | ||
37 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | ||
38 | FileLoaderDelegate(self).relevant_crates(file_id) | ||
39 | } | ||
40 | } | ||