Refactor: shared tree-sitter traversal helpers (B / without sview) - #8
Merged
Conversation
Extract common parser setup (parse), AST traversal (collect_items), and preview extraction (ast_preview) into src/tree.rs as shared helpers. Both rust.rs and javascript.rs now use these shared helpers, keeping only language-specific node classification, naming, and preview logic local. - tree.rs: add parse(), collect_items(), ast_preview() - rust.rs: use shared helpers; test-attribute detection via prev_named_sibling - javascript.rs: use shared helpers; remove duplicate traversal/preview code All 23 tests pass. cargo fmt --check clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A/B analysis report — issue #2
Task: refactor
sviewto introduce shared tree-sitter traversal helpers for the Rust and JavaScript/TypeScript analyzers.Candidates
sviewskillcargo fmt --check,cargo testpassedsviewskillcargo fmt --check,cargo testpassedImplementation comparison
src/traverse.rsmodule with aNodeClassifiertrait and mutable sibling-observation hook, then wires Rust and JavaScript analyzers through it. This is flexible, but adds a second tree-related module next to the existingsrc/tree.rsand more abstraction surface.src/tree.rsmodule withparse(),collect_items(), andast_preview(), then keeps language-specific classification local tosrc/rust.rsandsrc/javascript.rs. This is smaller and aligns with the shared tree-building helper introduced by the previous refactor.sview observations
A reports that
sviewprovided a compact structural map and helped identify duplicated parser/traversal/preview boundaries. However, issue #2 still involves small source files, so thesviewoverview did not translate into lower runtime cost: A used ~42% more tokens and 20 more model rounds than B, with similar self-counted tool-call volume.Decision
Recommendation: merge B (#8) and close/supersede A (#9).
Rationale: B achieves the same behavior with fewer files changed, less new abstraction, lower token cost, fewer model rounds, and about half the elapsed time. A is a useful experiment sample showing that
sviewhelped orientation, but this task size still did not produce a measurable efficiency win.