aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/test_db.rs59
1 files changed, 24 insertions, 35 deletions
diff --git a/crates/ra_hir/src/test_db.rs b/crates/ra_hir/src/test_db.rs
index 047a27aaf..84a2bf02b 100644
--- a/crates/ra_hir/src/test_db.rs
+++ b/crates/ra_hir/src/test_db.rs
@@ -5,10 +5,7 @@ use std::{panic, sync::Arc};
5use hir_def::{db::DefDatabase2, ModuleId}; 5use hir_def::{db::DefDatabase2, ModuleId};
6use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
7use parking_lot::Mutex; 7use parking_lot::Mutex;
8use ra_db::{ 8use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase};
9 salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase,
10 SourceRootId,
11};
12 9
13use crate::{db, debug::HirDebugHelper}; 10use crate::{db, debug::HirDebugHelper};
14 11
@@ -21,12 +18,34 @@ use crate::{db, debug::HirDebugHelper};
21 db::DefDatabase2Storage, 18 db::DefDatabase2Storage,
22 db::HirDatabaseStorage 19 db::HirDatabaseStorage
23)] 20)]
24#[derive(Debug)] 21#[derive(Debug, Default)]
25pub struct TestDB { 22pub struct TestDB {
26 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>, 23 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>,
27 runtime: salsa::Runtime<TestDB>, 24 runtime: salsa::Runtime<TestDB>,
28} 25}
29 26
27impl salsa::Database for TestDB {
28 fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> {
29 &self.runtime
30 }
31
32 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
33 let mut events = self.events.lock();
34 if let Some(events) = &mut *events {
35 events.push(event());
36 }
37 }
38}
39
40impl salsa::ParallelDatabase for TestDB {
41 fn snapshot(&self) -> salsa::Snapshot<TestDB> {
42 salsa::Snapshot::new(TestDB {
43 events: Default::default(),
44 runtime: self.runtime.snapshot(self),
45 })
46 }
47}
48
30impl panic::RefUnwindSafe for TestDB {} 49impl panic::RefUnwindSafe for TestDB {}
31 50
32impl FileLoader for TestDB { 51impl FileLoader for TestDB {
@@ -77,36 +96,6 @@ impl TestDB {
77 } 96 }
78} 97}
79 98
80impl salsa::Database for TestDB {
81 fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> {
82 &self.runtime
83 }
84
85 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
86 let mut events = self.events.lock();
87 if let Some(events) = &mut *events {
88 events.push(event());
89 }
90 }
91}
92
93impl Default for TestDB {
94 fn default() -> TestDB {
95 let mut db = TestDB { events: Default::default(), runtime: salsa::Runtime::default() };
96 db.set_crate_graph(Default::default());
97 db
98 }
99}
100
101impl salsa::ParallelDatabase for TestDB {
102 fn snapshot(&self) -> salsa::Snapshot<TestDB> {
103 salsa::Snapshot::new(TestDB {
104 events: Default::default(),
105 runtime: self.runtime.snapshot(self),
106 })
107 }
108}
109
110impl TestDB { 99impl TestDB {
111 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> { 100 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> {
112 *self.events.lock() = Some(Vec::new()); 101 *self.events.lock() = Some(Vec::new());