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