diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-02 14:36:52 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-02 14:36:52 +0100 |
commit | 0a758a2c4803c7ecc956d2aa6ed2ce48c4e4edd9 (patch) | |
tree | 97952861d81d1d5d4de49899c0d4e8da96796dc2 /crates/ra_syntax/src/syntax_node.rs | |
parent | 78f38a20fd53ccab18b1c4b7dda217b5bfb61c8f (diff) | |
parent | 7d6bd5d1379061180e771f7b833a9fecdc85a0b8 (diff) |
Merge #1090
1090: always show token text r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/syntax_node.rs')
-rw-r--r-- | crates/ra_syntax/src/syntax_node.rs | 21 |
1 files changed, 10 insertions, 11 deletions
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>); | |||
319 | impl<'a> fmt::Debug for SyntaxToken<'a> { | 319 | impl<'a> fmt::Debug for SyntaxToken<'a> { |
320 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 320 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
321 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; | 321 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; |
322 | if has_short_text(self.kind()) { | 322 | if self.text().len() < 25 { |
323 | write!(fmt, " \"{}\"", self.text())?; | 323 | return write!(fmt, " {:?}", self.text()); |
324 | } | 324 | } |
325 | Ok(()) | 325 | let text = self.text().as_str(); |
326 | for idx in 21..25 { | ||
327 | if text.is_char_boundary(idx) { | ||
328 | let text = format!("{} ...", &text[..idx]); | ||
329 | return write!(fmt, " {:?}", text); | ||
330 | } | ||
331 | } | ||
332 | unreachable!() | ||
326 | } | 333 | } |
327 | } | 334 | } |
328 | 335 | ||
@@ -499,14 +506,6 @@ impl<'a> Iterator for SyntaxElementChildren<'a> { | |||
499 | } | 506 | } |
500 | } | 507 | } |
501 | 508 | ||
502 | fn has_short_text(kind: SyntaxKind) -> bool { | ||
503 | use crate::SyntaxKind::*; | ||
504 | match kind { | ||
505 | IDENT | LIFETIME | INT_NUMBER | FLOAT_NUMBER => true, | ||
506 | _ => false, | ||
507 | } | ||
508 | } | ||
509 | |||
510 | pub struct SyntaxTreeBuilder { | 509 | pub struct SyntaxTreeBuilder { |
511 | errors: Vec<SyntaxError>, | 510 | errors: Vec<SyntaxError>, |
512 | inner: GreenNodeBuilder<RaTypes>, | 511 | inner: GreenNodeBuilder<RaTypes>, |