daipendency_testing/
debugging.rs1use tree_sitter::Node;
2
3pub fn debug_node(node: &Node, source_code: &str) -> String {
14 debug_node_with_indentation(node, source_code, 0)
15}
16
17fn debug_node_with_indentation(node: &Node, source_code: &str, indent: usize) -> String {
18 let mut result = String::new();
19 let indent_str = " ".repeat(indent);
20
21 result.push_str(&format!(
22 "{}{:?}: {}\n",
23 indent_str,
24 node,
25 node.utf8_text(source_code.as_bytes()).unwrap()
26 ));
27
28 let mut cursor = node.walk();
29 for child in node.children(&mut cursor) {
30 result.push_str(&debug_node_with_indentation(
31 &child,
32 source_code,
33 indent + 2,
34 ));
35 }
36
37 result
38}