From 7d6bd5d1379061180e771f7b833a9fecdc85a0b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 2 Apr 2019 14:04:23 +0300 Subject: always show token text --- crates/ra_syntax/src/syntax_node.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index be181d0ae..a88a348ad 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -319,10 +319,17 @@ pub struct SyntaxToken<'a>(pub(crate) rowan::SyntaxToken<'a, RaTypes>); impl<'a> fmt::Debug for SyntaxToken<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; - if has_short_text(self.kind()) { - write!(fmt, " \"{}\"", self.text())?; + if self.text().len() < 25 { + return write!(fmt, " {:?}", self.text()); } - Ok(()) + let text = self.text().as_str(); + for idx in 21..25 { + if text.is_char_boundary(idx) { + let text = format!("{} ...", &text[..idx]); + return write!(fmt, " {:?}", text); + } + } + unreachable!() } } @@ -499,14 +506,6 @@ impl<'a> Iterator for SyntaxElementChildren<'a> { } } -fn has_short_text(kind: SyntaxKind) -> bool { - use crate::SyntaxKind::*; - match kind { - IDENT | LIFETIME | INT_NUMBER | FLOAT_NUMBER => true, - _ => false, - } -} - pub struct SyntaxTreeBuilder { errors: Vec, inner: GreenNodeBuilder, -- cgit v1.2.3