aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_expand/src/lib.rs3
-rw-r--r--crates/ra_hir_expand/src/test_db.rs50
2 files changed, 53 insertions, 0 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 126d12fbb..f514a15e4 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -26,6 +26,9 @@ use ra_syntax::{
26use crate::ast_id_map::FileAstId; 26use crate::ast_id_map::FileAstId;
27use crate::builtin_macro::BuiltinExpander; 27use crate::builtin_macro::BuiltinExpander;
28 28
29#[cfg(test)]
30mod test_db;
31
29/// Input to the analyzer is a set of files, where each file is identified by 32/// Input to the analyzer is a set of files, where each file is identified by
30/// `FileId` and contains source code. However, another source of source code in 33/// `FileId` and contains source code. However, another source of source code in
31/// Rust are macros: each macro can be thought of as producing a "temporary 34/// Rust are macros: each macro can be thought of as producing a "temporary
diff --git a/crates/ra_hir_expand/src/test_db.rs b/crates/ra_hir_expand/src/test_db.rs
new file mode 100644
index 000000000..d23e75d9e
--- /dev/null
+++ b/crates/ra_hir_expand/src/test_db.rs
@@ -0,0 +1,50 @@
1//! Database used for testing `hir_expand`.
2
3use std::{
4 panic,
5 sync::{Arc, Mutex},
6};
7
8use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath};
9
10#[salsa::database(
11 ra_db::SourceDatabaseExtStorage,
12 ra_db::SourceDatabaseStorage,
13 crate::db::AstDatabaseStorage
14)]
15#[derive(Debug, Default)]
16pub struct TestDB {
17 runtime: salsa::Runtime<TestDB>,
18 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>,
19}
20
21impl salsa::Database for TestDB {
22 fn salsa_runtime(&self) -> &salsa::Runtime<Self> {
23 &self.runtime
24 }
25
26 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
27 let mut events = self.events.lock().unwrap();
28 if let Some(events) = &mut *events {
29 events.push(event());
30 }
31 }
32}
33
34impl panic::RefUnwindSafe for TestDB {}
35
36impl FileLoader for TestDB {
37 fn file_text(&self, file_id: FileId) -> Arc<String> {
38 FileLoaderDelegate(self).file_text(file_id)
39 }
40 fn resolve_relative_path(
41 &self,
42 anchor: FileId,
43 relative_path: &RelativePath,
44 ) -> Option<FileId> {
45 FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path)
46 }
47 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {
48 FileLoaderDelegate(self).relevant_crates(file_id)
49 }
50}