aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/fuzz.rs6
-rw-r--r--crates/ra_syntax/src/lib.rs2
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs4
-rw-r--r--crates/ra_syntax/src/syntax_node.rs56
-rw-r--r--crates/ra_syntax/src/validation.rs4
5 files changed, 32 insertions, 40 deletions
diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs
index 716925b2f..a9146c4f8 100644
--- a/crates/ra_syntax/src/fuzz.rs
+++ b/crates/ra_syntax/src/fuzz.rs
@@ -52,9 +52,9 @@ impl CheckReparse {
52 new_parse.tree().syntax().descendants().zip(full_reparse.tree().syntax().descendants()) 52 new_parse.tree().syntax().descendants().zip(full_reparse.tree().syntax().descendants())
53 { 53 {
54 if (a.kind(), a.range()) != (b.kind(), b.range()) { 54 if (a.kind(), a.range()) != (b.kind(), b.range()) {
55 eprint!("original:\n{}", parse.tree().syntax().debug_dump()); 55 eprint!("original:\n{:#?}", parse.tree().syntax());
56 eprint!("reparsed:\n{}", new_parse.tree().syntax().debug_dump()); 56 eprint!("reparsed:\n{:#?}", new_parse.tree().syntax());
57 eprint!("full reparse:\n{}", full_reparse.tree().syntax().debug_dump()); 57 eprint!("full reparse:\n{:#?}", full_reparse.tree().syntax());
58 assert_eq!( 58 assert_eq!(
59 format!("{:?}", a), 59 format!("{:?}", a),
60 format!("{:?}", b), 60 format!("{:?}", b),
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 604abe5c6..605350ac4 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -114,7 +114,7 @@ impl Parse<SyntaxNode> {
114 114
115impl Parse<SourceFile> { 115impl Parse<SourceFile> {
116 pub fn debug_dump(&self) -> String { 116 pub fn debug_dump(&self) -> String {
117 let mut buf = self.tree().syntax().debug_dump(); 117 let mut buf = format!("{:#?}", self.tree().syntax());
118 for err in self.errors.iter() { 118 for err in self.errors.iter() {
119 writeln!(buf, "error {:?}: {}", err.location(), err.kind()).unwrap(); 119 writeln!(buf, "error {:?}: {}", err.location(), err.kind()).unwrap();
120 } 120 }
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index b4ad9e019..c7183299b 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -188,8 +188,8 @@ mod tests {
188 }; 188 };
189 189
190 assert_eq_text!( 190 assert_eq_text!(
191 &fully_reparsed.tree().syntax().debug_dump(), 191 &format!("{:#?}", fully_reparsed.tree().syntax()),
192 &incrementally_reparsed.tree().syntax().debug_dump(), 192 &format!("{:#?}", incrementally_reparsed.tree().syntax()),
193 ); 193 );
194 } 194 }
195 195
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs
index 51bae04de..3b20e96e2 100644
--- a/crates/ra_syntax/src/syntax_node.rs
+++ b/crates/ra_syntax/src/syntax_node.rs
@@ -6,11 +6,7 @@
6//! The *real* implementation is in the (language-agnostic) `rowan` crate, this 6//! The *real* implementation is in the (language-agnostic) `rowan` crate, this
7//! modules just wraps its API. 7//! modules just wraps its API.
8 8
9use std::{ 9use std::{fmt, iter::successors, ops::RangeInclusive};
10 fmt::{self, Write},
11 iter::successors,
12 ops::RangeInclusive,
13};
14 10
15use ra_parser::ParseError; 11use ra_parser::ParseError;
16use rowan::GreenNodeBuilder; 12use rowan::GreenNodeBuilder;
@@ -36,8 +32,29 @@ pub enum InsertPosition<T> {
36pub struct SyntaxNode(pub(crate) rowan::cursor::SyntaxNode); 32pub struct SyntaxNode(pub(crate) rowan::cursor::SyntaxNode);
37 33
38impl fmt::Debug for SyntaxNode { 34impl fmt::Debug for SyntaxNode {
39 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 write!(fmt, "{:?}@{:?}", self.kind(), self.range()) 36 if f.alternate() {
37 let mut level = 0;
38 for event in self.preorder_with_tokens() {
39 match event {
40 WalkEvent::Enter(element) => {
41 for _ in 0..level {
42 write!(f, " ")?;
43 }
44 match element {
45 SyntaxElement::Node(node) => writeln!(f, "{:?}", node)?,
46 SyntaxElement::Token(token) => writeln!(f, "{:?}", token)?,
47 }
48 level += 1;
49 }
50 WalkEvent::Leave(_) => level -= 1,
51 }
52 }
53 assert_eq!(level, 0);
54 Ok(())
55 } else {
56 write!(f, "{:?}@{:?}", self.kind(), self.range())
57 }
41 } 58 }
42} 59}
43 60
@@ -173,31 +190,6 @@ impl SyntaxNode {
173 }) 190 })
174 } 191 }
175 192
176 pub fn debug_dump(&self) -> String {
177 let mut level = 0;
178 let mut buf = String::new();
179
180 for event in self.preorder_with_tokens() {
181 match event {
182 WalkEvent::Enter(element) => {
183 for _ in 0..level {
184 buf.push_str(" ");
185 }
186 match element {
187 SyntaxElement::Node(node) => writeln!(buf, "{:?}", node).unwrap(),
188 SyntaxElement::Token(token) => writeln!(buf, "{:?}", token).unwrap(),
189 }
190 level += 1;
191 }
192 WalkEvent::Leave(_) => level -= 1,
193 }
194 }
195
196 assert_eq!(level, 0);
197
198 buf
199 }
200
201 pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { 193 pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode {
202 self.0.replace_with(replacement) 194 self.0.replace_with(replacement)
203 } 195 }
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index 7140d10c3..943f88de9 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -89,9 +89,9 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
89 assert_eq!( 89 assert_eq!(
90 node.parent(), 90 node.parent(),
91 pair.parent(), 91 pair.parent(),
92 "\nunpaired curleys:\n{}\n{}\n", 92 "\nunpaired curleys:\n{}\n{:#?}\n",
93 root.text(), 93 root.text(),
94 root.debug_dump(), 94 root,
95 ); 95 );
96 assert!( 96 assert!(
97 node.next_sibling().is_none() && pair.prev_sibling().is_none(), 97 node.next_sibling().is_none() && pair.prev_sibling().is_none(),