use tree_sitter::Node;
pub fn debug_node(node: &Node, source_code: &str) -> String {
debug_node_with_indentation(node, source_code, 0)
}
fn debug_node_with_indentation(node: &Node, source_code: &str, indent: usize) -> String {
let mut result = String::new();
let indent_str = " ".repeat(indent);
result.push_str(&format!(
"{}{:?}: {}\n",
indent_str,
node,
node.utf8_text(source_code.as_bytes()).unwrap()
));
let mut cursor = node.walk();
for child in node.children(&mut cursor) {
result.push_str(&debug_node_with_indentation(
&child,
source_code,
indent + 2,
));
}
result
}