From 2e722ec54b3503e2b2f411959fffb63ef9f1a334 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 29 May 2019 10:12:08 +0300 Subject: show error offsets in tests --- crates/ra_syntax/src/lib.rs | 2 +- crates/ra_syntax/src/syntax_error.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 930a643b7..8c0ba6f2d 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -76,7 +76,7 @@ impl Parse { pub fn debug_dump(&self) -> String { let mut buf = self.tree.syntax().debug_dump(); for err in self.errors.iter() { - writeln!(buf, "err: `{}`", err).unwrap(); + writeln!(buf, "error {:?}: {}", err.location(), err.kind()).unwrap(); } buf } diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index 27e12293b..67deee1be 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -13,7 +13,7 @@ pub struct SyntaxError { location: Location, } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Clone, PartialEq, Eq, Hash)] pub enum Location { Offset(TextUnit), Range(TextRange), @@ -31,6 +31,15 @@ impl Into for TextRange { } } +impl fmt::Debug for Location { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Location::Offset(it) => fmt::Debug::fmt(it, f), + Location::Range(it) => fmt::Debug::fmt(it, f), + } + } +} + impl SyntaxError { pub fn new>(kind: SyntaxErrorKind, loc: L) -> SyntaxError { SyntaxError { kind, location: loc.into() } -- cgit v1.2.3