From fd7819c3c09161986c3e1398d546e7503886760b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 Nov 2019 22:29:51 +0300 Subject: Simplify --- crates/ra_hir/src/test_db.rs | 59 ++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) (limited to 'crates/ra_hir/src/test_db.rs') 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}; use hir_def::{db::DefDatabase2, ModuleId}; use hir_expand::diagnostics::DiagnosticSink; use parking_lot::Mutex; -use ra_db::{ - salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase, - SourceRootId, -}; +use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase}; use crate::{db, debug::HirDebugHelper}; @@ -21,12 +18,34 @@ use crate::{db, debug::HirDebugHelper}; db::DefDatabase2Storage, db::HirDatabaseStorage )] -#[derive(Debug)] +#[derive(Debug, Default)] pub struct TestDB { events: Mutex>>>, runtime: salsa::Runtime, } +impl salsa::Database for TestDB { + fn salsa_runtime(&self) -> &salsa::Runtime { + &self.runtime + } + + fn salsa_event(&self, event: impl Fn() -> salsa::Event) { + let mut events = self.events.lock(); + if let Some(events) = &mut *events { + events.push(event()); + } + } +} + +impl salsa::ParallelDatabase for TestDB { + fn snapshot(&self) -> salsa::Snapshot { + salsa::Snapshot::new(TestDB { + events: Default::default(), + runtime: self.runtime.snapshot(self), + }) + } +} + impl panic::RefUnwindSafe for TestDB {} impl FileLoader for TestDB { @@ -77,36 +96,6 @@ impl TestDB { } } -impl salsa::Database for TestDB { - fn salsa_runtime(&self) -> &salsa::Runtime { - &self.runtime - } - - fn salsa_event(&self, event: impl Fn() -> salsa::Event) { - let mut events = self.events.lock(); - if let Some(events) = &mut *events { - events.push(event()); - } - } -} - -impl Default for TestDB { - fn default() -> TestDB { - let mut db = TestDB { events: Default::default(), runtime: salsa::Runtime::default() }; - db.set_crate_graph(Default::default()); - db - } -} - -impl salsa::ParallelDatabase for TestDB { - fn snapshot(&self) -> salsa::Snapshot { - salsa::Snapshot::new(TestDB { - events: Default::default(), - runtime: self.runtime.snapshot(self), - }) - } -} - impl TestDB { pub fn log(&self, f: impl FnOnce()) -> Vec> { *self.events.lock() = Some(Vec::new()); -- cgit v1.2.3