move debug_dump to fmt::Debug
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user