refactor(native): extract generic walk_tree to deduplicate extractor boilerplate#703
refactor(native): extract generic walk_tree to deduplicate extractor boilerplate#703carlos-alm merged 2 commits intomainfrom
Conversation
…pth duplication The walk_node/walk_node_depth pattern was duplicated identically across all 9 language extractors (~190 lines of boilerplate). Each extractor repeated the same depth check, match dispatch, and child traversal loop — only the match arms differed. Add a generic `walk_tree<F>` function to helpers.rs that handles depth limiting and child recursion, accepting a closure for language-specific node matching. Refactor all 9 extractors and 7 type map walkers to use it. Zero-cost abstraction (monomorphized, no dyn dispatch).
|
Claude finished @carlos-alm's task —— View job PR Review: Native Tree Walker Refactoring ⭐⭐⭐⭐Todo List:
Root Cause AnalysisProblem Being Solved: Elimination of code duplication across Rust language extractors. The Why This Approach: Generic function Risk Assessment: Very low risk. This is pure refactoring with no behavioral changes. All tests pass and the generic function perfectly replicates the previous logic. Backlog Compliance
Code Quality AssessmentExcellent refactoring execution:
Minor Observations
Critical ConcernsNone identified. This is exemplary refactoring work. Final Recommendation
This PR demonstrates exactly how technical debt should be addressed - identify the pattern, extract the right abstraction, apply consistently, verify with tests. Well done. |
Greptile SummaryThis PR introduces a single generic Key correctness checks:
Confidence Score: 5/5Safe to merge — pure refactoring with no behavioral changes, verified against all three structural patterns in the diff. All changed call-sites produce identical traversal order, depth limits, and symbol emission. No P0/P1 findings. 272 parser tests + 562 integration tests pass according to the test plan. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["extract() — SymbolExtractor"] --> B["walk_tree(root, source, symbols, match_X_node)"]
A --> C["walk_ast_nodes_with_config(...)"]
A --> D["walk_tree(root, source, symbols, match_X_type_map)"]
B --> E["walk_tree_depth(node, source, symbols, depth=0, &match_X_node)"]
D --> F["walk_tree_depth(node, source, symbols, depth=0, &match_X_type_map)"]
E --> G{depth >= MAX_WALK_DEPTH?}
G -- Yes --> H[return]
G -- No --> I["match_X_node(node, source, symbols, depth)"]
I --> J["for each child: walk_tree_depth(child, depth+1, &match_X_node)"]
J --> E
Reviews (1): Last reviewed commit: "refactor(native): extract generic walk_t..." | Re-trigger Greptile |
Summary
walk_tree<F>generic function tohelpers.rs— a depth-limited tree walker that accepts a closure for language-specific node matching, then handles the depth check and child recursion automaticallywalk_node/walk_node_depthpattern across all 9 language extractors withwalk_tree+ amatch_X_nodefunctionextract_X_type_map/extract_X_type_map_depth) across 7 extractors with same patterndyndispatch)Test plan
cargo check(blocked by missing MSVC build tools on dev machine — CI will validate)