move debug_dump to fmt::Debug
This commit is contained in:
parent
e18f8495d6
commit
6d5d82e412
10 changed files with 42 additions and 50 deletions
|
|
@ -55,7 +55,7 @@ fn main() -> Result<()> {
|
|||
let _p = profile("parsing");
|
||||
let file = file()?;
|
||||
if !matches.is_present("no-dump") {
|
||||
println!("{}", file.syntax().debug_dump());
|
||||
println!("{:#?}", file.syntax());
|
||||
}
|
||||
std::mem::forget(file);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -843,7 +843,7 @@ where
|
|||
let file_id = call_id.as_file(MacroFileKind::Expr);
|
||||
if let Some(node) = self.db.parse_or_expand(file_id) {
|
||||
if let Some(expr) = ast::Expr::cast(node) {
|
||||
log::debug!("macro expansion {}", expr.syntax().debug_dump());
|
||||
log::debug!("macro expansion {:#?}", expr.syntax());
|
||||
let old_file_id =
|
||||
std::mem::replace(&mut self.current_file_id, file_id);
|
||||
let id = self.collect_expr(expr);
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ impl NavigationTarget {
|
|||
|
||||
pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget {
|
||||
let src = macro_call.source(db);
|
||||
log::debug!("nav target {}", src.ast.syntax().debug_dump());
|
||||
log::debug!("nav target {:#?}", src.ast.syntax());
|
||||
NavigationTarget::from_named(
|
||||
src.file_id.original_file(db),
|
||||
&src.ast,
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ pub(crate) fn syntax_tree(
|
|||
}
|
||||
};
|
||||
|
||||
node.debug_dump()
|
||||
format!("{:#?}", node)
|
||||
} else {
|
||||
parse.tree().syntax().debug_dump()
|
||||
format!("{:#?}", parse.tree().syntax())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St
|
|||
// If the "file" parsed without errors,
|
||||
// return its syntax
|
||||
if parsed.errors().is_empty() {
|
||||
return Some(parsed.tree().syntax().debug_dump());
|
||||
return Some(format!("{:#?}", parsed.tree().syntax()));
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ fn test_expand_to_item_list() {
|
|||
let expansion = expand(&rules, "structs!(Foo, Bar);");
|
||||
let tree = token_tree_to_macro_items(&expansion).unwrap().tree();
|
||||
assert_eq!(
|
||||
tree.syntax().debug_dump().trim(),
|
||||
format!("{:#?}", tree.syntax()).trim(),
|
||||
r#"
|
||||
MACRO_ITEMS@[0; 40)
|
||||
STRUCT_DEF@[0; 20)
|
||||
|
|
@ -531,7 +531,7 @@ fn test_tt_to_stmts() {
|
|||
let stmts = token_tree_to_macro_stmts(&expanded).unwrap().tree();
|
||||
|
||||
assert_eq!(
|
||||
stmts.syntax().debug_dump().trim(),
|
||||
format!("{:#?}", stmts.syntax()).trim(),
|
||||
r#"MACRO_STMTS@[0; 15)
|
||||
LET_STMT@[0; 7)
|
||||
LET_KW@[0; 3) "let"
|
||||
|
|
@ -669,7 +669,7 @@ fn test_expr_order() {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
expand_to_items(&rules, "foo! { 1 + 1 }").syntax().debug_dump().trim(),
|
||||
format!("{:#?}", expand_to_items(&rules, "foo! { 1 + 1 }").syntax()).trim(),
|
||||
r#"MACRO_ITEMS@[0; 15)
|
||||
FN_DEF@[0; 15)
|
||||
FN_KW@[0; 2) "fn"
|
||||
|
|
@ -1013,7 +1013,7 @@ fn test_vec() {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
expand_to_expr(&rules, r#"vec![1u32,2];"#).syntax().debug_dump().trim(),
|
||||
format!("{:#?}", expand_to_expr(&rules, r#"vec![1u32,2];"#).syntax()).trim(),
|
||||
r#"BLOCK_EXPR@[0; 45)
|
||||
BLOCK@[0; 45)
|
||||
L_CURLY@[0; 1) "{"
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ impl CheckReparse {
|
|||
new_parse.tree().syntax().descendants().zip(full_reparse.tree().syntax().descendants())
|
||||
{
|
||||
if (a.kind(), a.range()) != (b.kind(), b.range()) {
|
||||
eprint!("original:\n{}", parse.tree().syntax().debug_dump());
|
||||
eprint!("reparsed:\n{}", new_parse.tree().syntax().debug_dump());
|
||||
eprint!("full reparse:\n{}", full_reparse.tree().syntax().debug_dump());
|
||||
eprint!("original:\n{:#?}", parse.tree().syntax());
|
||||
eprint!("reparsed:\n{:#?}", new_parse.tree().syntax());
|
||||
eprint!("full reparse:\n{:#?}", full_reparse.tree().syntax());
|
||||
assert_eq!(
|
||||
format!("{:?}", a),
|
||||
format!("{:?}", b),
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ impl Parse<SyntaxNode> {
|
|||
|
||||
impl Parse<SourceFile> {
|
||||
pub fn debug_dump(&self) -> String {
|
||||
let mut buf = self.tree().syntax().debug_dump();
|
||||
let mut buf = format!("{:#?}", self.tree().syntax());
|
||||
for err in self.errors.iter() {
|
||||
writeln!(buf, "error {:?}: {}", err.location(), err.kind()).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,8 +188,8 @@ mod tests {
|
|||
};
|
||||
|
||||
assert_eq_text!(
|
||||
&fully_reparsed.tree().syntax().debug_dump(),
|
||||
&incrementally_reparsed.tree().syntax().debug_dump(),
|
||||
&format!("{:#?}", fully_reparsed.tree().syntax()),
|
||||
&format!("{:#?}", incrementally_reparsed.tree().syntax()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,7 @@
|
|||
//! The *real* implementation is in the (language-agnostic) `rowan` crate, this
|
||||
//! modules just wraps its API.
|
||||
|
||||
use std::{
|
||||
fmt::{self, Write},
|
||||
iter::successors,
|
||||
ops::RangeInclusive,
|
||||
};
|
||||
use std::{fmt, iter::successors, ops::RangeInclusive};
|
||||
|
||||
use ra_parser::ParseError;
|
||||
use rowan::GreenNodeBuilder;
|
||||
|
|
@ -36,8 +32,29 @@ pub enum InsertPosition<T> {
|
|||
pub struct SyntaxNode(pub(crate) rowan::cursor::SyntaxNode);
|
||||
|
||||
impl fmt::Debug for SyntaxNode {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{:?}@{:?}", self.kind(), self.range())
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if f.alternate() {
|
||||
let mut level = 0;
|
||||
for event in self.preorder_with_tokens() {
|
||||
match event {
|
||||
WalkEvent::Enter(element) => {
|
||||
for _ in 0..level {
|
||||
write!(f, " ")?;
|
||||
}
|
||||
match element {
|
||||
SyntaxElement::Node(node) => writeln!(f, "{:?}", node)?,
|
||||
SyntaxElement::Token(token) => writeln!(f, "{:?}", token)?,
|
||||
}
|
||||
level += 1;
|
||||
}
|
||||
WalkEvent::Leave(_) => level -= 1,
|
||||
}
|
||||
}
|
||||
assert_eq!(level, 0);
|
||||
Ok(())
|
||||
} else {
|
||||
write!(f, "{:?}@{:?}", self.kind(), self.range())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,31 +190,6 @@ impl SyntaxNode {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn debug_dump(&self) -> String {
|
||||
let mut level = 0;
|
||||
let mut buf = String::new();
|
||||
|
||||
for event in self.preorder_with_tokens() {
|
||||
match event {
|
||||
WalkEvent::Enter(element) => {
|
||||
for _ in 0..level {
|
||||
buf.push_str(" ");
|
||||
}
|
||||
match element {
|
||||
SyntaxElement::Node(node) => writeln!(buf, "{:?}", node).unwrap(),
|
||||
SyntaxElement::Token(token) => writeln!(buf, "{:?}", token).unwrap(),
|
||||
}
|
||||
level += 1;
|
||||
}
|
||||
WalkEvent::Leave(_) => level -= 1,
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(level, 0);
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode {
|
||||
self.0.replace_with(replacement)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,9 +89,9 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
|
|||
assert_eq!(
|
||||
node.parent(),
|
||||
pair.parent(),
|
||||
"\nunpaired curleys:\n{}\n{}\n",
|
||||
"\nunpaired curleys:\n{}\n{:#?}\n",
|
||||
root.text(),
|
||||
root.debug_dump(),
|
||||
root,
|
||||
);
|
||||
assert!(
|
||||
node.next_sibling().is_none() && pair.prev_sibling().is_none(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue