Skip to content

Commit

Permalink
fix(node_with_source): add print_node_tree() method on `NodeWithSou…
Browse files Browse the repository at this point in the history
…rce`
  • Loading branch information
Alex-ley-scrub committed Nov 15, 2024
1 parent a152297 commit 8e6a695
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions crates/util/src/node_with_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ impl<'a> NodeWithSource<'a> {
end_byte: ts_range.end_byte(),
}
}

pub fn print_node_tree(&self) {
let mut stack = vec![(self.node.clone(), 0)];
while let Some((node, depth)) = stack.pop() {
let sort_id = node.kind_id();
println!("{:indent$}{}: {:?}", "", sort_id, node, indent = depth * 2);
for i in (0..node.child_count()).rev() {
if let Some(child) = node.child(i) {
stack.push((child, depth + 1));
}
}
}
}
}

impl<'a> PartialEq for NodeWithSource<'a> {
Expand Down
2 changes: 1 addition & 1 deletion resources/add_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def main(args: Namespace):
with open(grammar_js_path, "w") as f:
f.write(updated_grammar_js)

# check if tree-sitter is installed:
# check if node is installed:
try:
output = check_output(["node", "--version"], cwd=repo_path).decode().strip()
print("using", output)
Expand Down

0 comments on commit 8e6a695

Please sign in to comment.