aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/test_db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/test_db.rs')
-rw-r--r--crates/ra_hir_ty/src/test_db.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs
index fddf0604d..dc447955f 100644
--- a/crates/ra_hir_ty/src/test_db.rs
+++ b/crates/ra_hir_ty/src/test_db.rs
@@ -1,7 +1,7 @@
1//! Database used for testing `hir`. 1//! Database used for testing `hir`.
2 2
3use std::{ 3use std::{
4 panic, 4 fmt, panic,
5 sync::{Arc, Mutex}, 5 sync::{Arc, Mutex},
6}; 6};
7 7
@@ -26,10 +26,15 @@ use crate::{
26 hir_def::db::DefDatabaseStorage, 26 hir_def::db::DefDatabaseStorage,
27 crate::db::HirDatabaseStorage 27 crate::db::HirDatabaseStorage
28)] 28)]
29#[derive(Debug, Default)] 29#[derive(Default)]
30pub struct TestDB { 30pub struct TestDB {
31 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>, 31 storage: salsa::Storage<TestDB>,
32 runtime: salsa::Runtime<TestDB>, 32 events: Mutex<Option<Vec<salsa::Event>>>,
33}
34impl fmt::Debug for TestDB {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 f.debug_struct("TestDB").finish()
37 }
33} 38}
34 39
35impl Upcast<dyn AstDatabase> for TestDB { 40impl Upcast<dyn AstDatabase> for TestDB {
@@ -45,18 +50,10 @@ impl Upcast<dyn DefDatabase> for TestDB {
45} 50}
46 51
47impl salsa::Database for TestDB { 52impl salsa::Database for TestDB {
48 fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> { 53 fn salsa_event(&self, event: salsa::Event) {
49 &self.runtime
50 }
51
52 fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> {
53 &mut self.runtime
54 }
55
56 fn salsa_event(&self, event: impl Fn() -> salsa::Event<TestDB>) {
57 let mut events = self.events.lock().unwrap(); 54 let mut events = self.events.lock().unwrap();
58 if let Some(events) = &mut *events { 55 if let Some(events) = &mut *events {
59 events.push(event()); 56 events.push(event);
60 } 57 }
61 } 58 }
62} 59}
@@ -64,8 +61,8 @@ impl salsa::Database for TestDB {
64impl salsa::ParallelDatabase for TestDB { 61impl salsa::ParallelDatabase for TestDB {
65 fn snapshot(&self) -> salsa::Snapshot<TestDB> { 62 fn snapshot(&self) -> salsa::Snapshot<TestDB> {
66 salsa::Snapshot::new(TestDB { 63 salsa::Snapshot::new(TestDB {
64 storage: self.storage.snapshot(),
67 events: Default::default(), 65 events: Default::default(),
68 runtime: self.runtime.snapshot(self),
69 }) 66 })
70 } 67 }
71} 68}
@@ -182,7 +179,7 @@ impl TestDB {
182} 179}
183 180
184impl TestDB { 181impl TestDB {
185 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<TestDB>> { 182 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> {
186 *self.events.lock().unwrap() = Some(Vec::new()); 183 *self.events.lock().unwrap() = Some(Vec::new());
187 f(); 184 f();
188 self.events.lock().unwrap().take().unwrap() 185 self.events.lock().unwrap().take().unwrap()
@@ -196,7 +193,7 @@ impl TestDB {
196 // This pretty horrible, but `Debug` is the only way to inspect 193 // This pretty horrible, but `Debug` is the only way to inspect
197 // QueryDescriptor at the moment. 194 // QueryDescriptor at the moment.
198 salsa::EventKind::WillExecute { database_key } => { 195 salsa::EventKind::WillExecute { database_key } => {
199 Some(format!("{:?}", database_key)) 196 Some(format!("{:?}", database_key.debug(self)))
200 } 197 }
201 _ => None, 198 _ => None,
202 }) 199 })