aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-20 10:48:24 +0100
committerAleksey Kladov <[email protected]>2019-07-20 10:48:24 +0100
commit6d5d82e412dea19ea48eecc6f7d5a4aa223a9599 (patch)
treeddc74569a2ed64c9ad7fb451b2f83e3a53f56dfe /crates
parente18f8495d6569f4fc0b7457b65a1d199cf7b5974 (diff)
move debug_dump to fmt::Debug
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cli/src/main.rs2
-rw-r--r--crates/ra_hir/src/expr.rs2
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs2
-rw-r--r--crates/ra_ide_api/src/syntax_tree.rs6
-rw-r--r--crates/ra_mbe/src/tests.rs8
-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
10 files changed, 42 insertions, 50 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 375e2f508..de8191ca3 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -55,7 +55,7 @@ fn main() -> Result<()> {
55 let _p = profile("parsing"); 55 let _p = profile("parsing");
56 let file = file()?; 56 let file = file()?;
57 if !matches.is_present("no-dump") { 57 if !matches.is_present("no-dump") {
58 println!("{}", file.syntax().debug_dump()); 58 println!("{:#?}", file.syntax());
59 } 59 }
60 std::mem::forget(file); 60 std::mem::forget(file);
61 } 61 }
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 66cb9633b..6eed67f50 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -843,7 +843,7 @@ where
843 let file_id = call_id.as_file(MacroFileKind::Expr); 843 let file_id = call_id.as_file(MacroFileKind::Expr);
844 if let Some(node) = self.db.parse_or_expand(file_id) { 844 if let Some(node) = self.db.parse_or_expand(file_id) {
845 if let Some(expr) = ast::Expr::cast(node) { 845 if let Some(expr) = ast::Expr::cast(node) {
846 log::debug!("macro expansion {}", expr.syntax().debug_dump()); 846 log::debug!("macro expansion {:#?}", expr.syntax());
847 let old_file_id = 847 let old_file_id =
848 std::mem::replace(&mut self.current_file_id, file_id); 848 std::mem::replace(&mut self.current_file_id, file_id);
849 let id = self.collect_expr(expr); 849 let id = self.collect_expr(expr);
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index 8aff5f2cd..c212ebf28 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -233,7 +233,7 @@ impl NavigationTarget {
233 233
234 pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget { 234 pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget {
235 let src = macro_call.source(db); 235 let src = macro_call.source(db);
236 log::debug!("nav target {}", src.ast.syntax().debug_dump()); 236 log::debug!("nav target {:#?}", src.ast.syntax());
237 NavigationTarget::from_named( 237 NavigationTarget::from_named(
238 src.file_id.original_file(db), 238 src.file_id.original_file(db),
239 &src.ast, 239 &src.ast,
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs
index 3d7373d02..ae1849aaa 100644
--- a/crates/ra_ide_api/src/syntax_tree.rs
+++ b/crates/ra_ide_api/src/syntax_tree.rs
@@ -25,9 +25,9 @@ pub(crate) fn syntax_tree(
25 } 25 }
26 }; 26 };
27 27
28 node.debug_dump() 28 format!("{:#?}", node)
29 } else { 29 } else {
30 parse.tree().syntax().debug_dump() 30 format!("{:#?}", parse.tree().syntax())
31 } 31 }
32} 32}
33 33
@@ -85,7 +85,7 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St
85 // If the "file" parsed without errors, 85 // If the "file" parsed without errors,
86 // return its syntax 86 // return its syntax
87 if parsed.errors().is_empty() { 87 if parsed.errors().is_empty() {
88 return Some(parsed.tree().syntax().debug_dump()); 88 return Some(format!("{:#?}", parsed.tree().syntax()));
89 } 89 }
90 90
91 None 91 None
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index 38a31109d..9151b6ecd 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -412,7 +412,7 @@ fn test_expand_to_item_list() {
412 let expansion = expand(&rules, "structs!(Foo, Bar);"); 412 let expansion = expand(&rules, "structs!(Foo, Bar);");
413 let tree = token_tree_to_macro_items(&expansion).unwrap().tree(); 413 let tree = token_tree_to_macro_items(&expansion).unwrap().tree();
414 assert_eq!( 414 assert_eq!(
415 tree.syntax().debug_dump().trim(), 415 format!("{:#?}", tree.syntax()).trim(),
416 r#" 416 r#"
417MACRO_ITEMS@[0; 40) 417MACRO_ITEMS@[0; 40)
418 STRUCT_DEF@[0; 20) 418 STRUCT_DEF@[0; 20)
@@ -531,7 +531,7 @@ fn test_tt_to_stmts() {
531 let stmts = token_tree_to_macro_stmts(&expanded).unwrap().tree(); 531 let stmts = token_tree_to_macro_stmts(&expanded).unwrap().tree();
532 532
533 assert_eq!( 533 assert_eq!(
534 stmts.syntax().debug_dump().trim(), 534 format!("{:#?}", stmts.syntax()).trim(),
535 r#"MACRO_STMTS@[0; 15) 535 r#"MACRO_STMTS@[0; 15)
536 LET_STMT@[0; 7) 536 LET_STMT@[0; 7)
537 LET_KW@[0; 3) "let" 537 LET_KW@[0; 3) "let"
@@ -669,7 +669,7 @@ fn test_expr_order() {
669 ); 669 );
670 670
671 assert_eq!( 671 assert_eq!(
672 expand_to_items(&rules, "foo! { 1 + 1 }").syntax().debug_dump().trim(), 672 format!("{:#?}", expand_to_items(&rules, "foo! { 1 + 1 }").syntax()).trim(),
673 r#"MACRO_ITEMS@[0; 15) 673 r#"MACRO_ITEMS@[0; 15)
674 FN_DEF@[0; 15) 674 FN_DEF@[0; 15)
675 FN_KW@[0; 2) "fn" 675 FN_KW@[0; 2) "fn"
@@ -1013,7 +1013,7 @@ fn test_vec() {
1013 ); 1013 );
1014 1014
1015 assert_eq!( 1015 assert_eq!(
1016 expand_to_expr(&rules, r#"vec![1u32,2];"#).syntax().debug_dump().trim(), 1016 format!("{:#?}", expand_to_expr(&rules, r#"vec![1u32,2];"#).syntax()).trim(),
1017 r#"BLOCK_EXPR@[0; 45) 1017 r#"BLOCK_EXPR@[0; 45)
1018 BLOCK@[0; 45) 1018 BLOCK@[0; 45)
1019 L_CURLY@[0; 1) "{" 1019 L_CURLY@[0; 1) "{"
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(),