aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ssr/src/lib.rs')
-rw-r--r--crates/ra_ssr/src/lib.rs42
1 files changed, 18 insertions, 24 deletions
diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs
index 422e15ee6..cca4576ce 100644
--- a/crates/ra_ssr/src/lib.rs
+++ b/crates/ra_ssr/src/lib.rs
@@ -6,9 +6,12 @@
6mod matching; 6mod matching;
7mod parsing; 7mod parsing;
8mod replacing; 8mod replacing;
9#[macro_use]
10mod errors;
9#[cfg(test)] 11#[cfg(test)]
10mod tests; 12mod tests;
11 13
14pub use crate::errors::SsrError;
12pub use crate::matching::Match; 15pub use crate::matching::Match;
13use crate::matching::{record_match_fails_reasons_scope, MatchFailureReason}; 16use crate::matching::{record_match_fails_reasons_scope, MatchFailureReason};
14use hir::Semantics; 17use hir::Semantics;
@@ -41,9 +44,6 @@ pub struct SsrPattern {
41 pattern: Option<SyntaxNode>, 44 pattern: Option<SyntaxNode>,
42} 45}
43 46
44#[derive(Debug, PartialEq)]
45pub struct SsrError(String);
46
47#[derive(Debug, Default)] 47#[derive(Debug, Default)]
48pub struct SsrMatches { 48pub struct SsrMatches {
49 pub matches: Vec<Match>, 49 pub matches: Vec<Match>,
@@ -201,9 +201,8 @@ impl<'db> MatchFinder<'db> {
201 ); 201 );
202 } 202 }
203 } 203 }
204 } else {
205 self.output_debug_for_nodes_at_range(&node, range, restrict_range, out);
206 } 204 }
205 self.output_debug_for_nodes_at_range(&node, range, restrict_range, out);
207 } 206 }
208 } 207 }
209} 208}
@@ -216,33 +215,28 @@ pub struct MatchDebugInfo {
216 matched: Result<Match, MatchFailureReason>, 215 matched: Result<Match, MatchFailureReason>,
217} 216}
218 217
219impl std::fmt::Display for SsrError {
220 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
221 write!(f, "Parse error: {}", self.0)
222 }
223}
224
225impl std::fmt::Debug for MatchDebugInfo { 218impl std::fmt::Debug for MatchDebugInfo {
226 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 219 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
227 write!(f, "========= PATTERN ==========\n")?; 220 match &self.matched {
221 Ok(_) => writeln!(f, "Node matched")?,
222 Err(reason) => writeln!(f, "Node failed to match because: {}", reason.reason)?,
223 }
224 writeln!(
225 f,
226 "============ AST ===========\n\
227 {:#?}",
228 self.node
229 )?;
230 writeln!(f, "========= PATTERN ==========")?;
228 match &self.pattern { 231 match &self.pattern {
229 Ok(pattern) => { 232 Ok(pattern) => {
230 write!(f, "{:#?}", pattern)?; 233 writeln!(f, "{:#?}", pattern)?;
231 } 234 }
232 Err(err) => { 235 Err(err) => {
233 write!(f, "{}", err.reason)?; 236 writeln!(f, "{}", err.reason)?;
234 } 237 }
235 } 238 }
236 write!( 239 writeln!(f, "============================")?;
237 f,
238 "\n============ AST ===========\n\
239 {:#?}\n============================\n",
240 self.node
241 )?;
242 match &self.matched {
243 Ok(_) => write!(f, "Node matched")?,
244 Err(reason) => write!(f, "Node failed to match because: {}", reason.reason)?,
245 }
246 Ok(()) 240 Ok(())
247 } 241 }
248} 242}