From 4a8679824b9ddf950e6754231755d5d065692c47 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Fri, 3 Jul 2020 13:15:00 +1000 Subject: SSR: Improve error reporting when a test fails --- crates/ra_ssr/src/lib.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/ra_ssr/src/lib.rs') diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs index d6862356d..cca4576ce 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ra_ssr/src/lib.rs @@ -201,9 +201,8 @@ impl<'db> MatchFinder<'db> { ); } } - } else { - self.output_debug_for_nodes_at_range(&node, range, restrict_range, out); } + self.output_debug_for_nodes_at_range(&node, range, restrict_range, out); } } } @@ -218,25 +217,26 @@ pub struct MatchDebugInfo { impl std::fmt::Debug for MatchDebugInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "========= PATTERN ==========\n")?; + match &self.matched { + Ok(_) => writeln!(f, "Node matched")?, + Err(reason) => writeln!(f, "Node failed to match because: {}", reason.reason)?, + } + writeln!( + f, + "============ AST ===========\n\ + {:#?}", + self.node + )?; + writeln!(f, "========= PATTERN ==========")?; match &self.pattern { Ok(pattern) => { - write!(f, "{:#?}", pattern)?; + writeln!(f, "{:#?}", pattern)?; } Err(err) => { - write!(f, "{}", err.reason)?; + writeln!(f, "{}", err.reason)?; } } - write!( - f, - "\n============ AST ===========\n\ - {:#?}\n============================\n", - self.node - )?; - match &self.matched { - Ok(_) => write!(f, "Node matched")?, - Err(reason) => write!(f, "Node failed to match because: {}", reason.reason)?, - } + writeln!(f, "============================")?; Ok(()) } } -- cgit v1.2.3