fix: extract new/throw/await/string/regex AST nodes in native engine#314
fix: extract new/throw/await/string/regex AST nodes in native engine#314carlos-alm merged 1 commit intomainfrom
Conversation
…306) The native Rust engine only extracted call_expression nodes, missing new/throw/await/string/regex kinds that the WASM engine captures via tree walking in ast.js. This caused `ast --kind new` (and similar) to return empty results when built with --engine native. Rust changes: - Add AstNode struct to types.rs with napi(object) derive - Add ast_nodes field to FileSymbols - Add walk_ast_nodes() in javascript.rs as a separate tree walk mirroring walkAst() in ast.js, with proper recursion control (no recurse for new/throw/await, recurse for string/regex) - Add truncate() helper for char-safe text truncation - Add 12 Rust unit tests covering all 5 kinds + edge cases JS changes: - normalizeNativeSymbols() maps the new astNodes field - buildAstNodes() adds native path: when _tree is absent but astNodes is populated, insert pre-extracted nodes directly - ast-nodes.test.js adds native engine test suite (auto-skips if installed native addon predates this change) Impact: 20 functions changed, 19 affected
|
Claude finished @carlos-alm's task —— View job PR Review: Native AST Node Extraction FixTodo List:
Phase 1: Root Cause Analysis ✅Problem Being Solved: The native Rust engine was only extracting Why This Approach: This fixes the actual root cause rather than masking symptoms. The issue was architectural - the native engine lacked the AST walking functionality that existed in the WASM path ( Risk Assessment: ✅ LOW RISK - This is a legitimate feature parity fix addressing a real functional gap. Phase 2: Configuration Change Detection ✅No Configuration Changes Found: ✅ No changes to:
This is purely a code implementation change with no rule relaxation or configuration modifications. Phase 3: Test Integrity ✅Test Changes Are Legitimate: ✅
No test expectations were lowered - only new functionality verification added. Phase 4: Code Quality ✅Rust Implementation: ✅ High Quality
JavaScript Integration: ✅ Well Architected
Architecture: ✅ Sound Design
Critical ConcernsNone Found - This is a well-implemented feature parity fix. Final Recommendation |
Greptile SummaryThis PR fixes a feature parity gap between the native Rust engine and WASM engine by implementing AST node extraction for Key changes:
Test coverage:
The implementation is clean, well-tested, and properly handles edge cases like Unicode truncation and trivial string filtering. Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Source Code] -->|Parse| B[Tree-sitter AST]
B -->|Native Engine| C[walk_ast_nodes in Rust]
B -->|WASM Engine| D[walkAst in JS]
C -->|Extract| E[AstNode Structs]
E -->|Add to| F[FileSymbols.ast_nodes]
F -->|N-API Bridge| G[normalizeNativeSymbols]
D -->|Extract| H[AST Rows]
G -->|symbols.astNodes| I[buildAstNodes]
I -->|Native Path| J[Consume Pre-extracted Nodes]
I -->|WASM Path| K[Walk Tree-sitter AST]
H -->|Direct| K
J -->|Insert| L[ast_nodes DB Table]
K -->|Insert| L
subgraph Rust[Rust Native Engine]
C
E
F
end
subgraph JS[JavaScript Layer]
G
I
D
end
subgraph AST Node Types
M[new expressions]
N[throw statements]
O[await expressions]
P[string literals]
Q[regex patterns]
end
Last reviewed commit: 79ec5c8 |
Summary
Fixes #306 — the native Rust engine only extracted
call_expressionnodes, missingnew/throw/await/string/regexAST kinds that the WASM engine captures via tree walking inast.js. This causedast --kind new(and similar) to return empty results when built with--engine native.AstNodestruct toFileSymbols, implementwalk_ast_nodes()injavascript.rsmirroringwalkAst()fromast.jswith proper recursion control (no recurse for new/throw/await to avoid double-counting, recurse for string/regex)normalizeNativeSymbols()maps the newastNodesfield;buildAstNodes()adds native path consuming pre-extracted nodes when_treeis absentTest plan
cargo testvalidates Rust unit testsnode src/cli.js build . --engine native && node src/cli.js ast --kind new -Tshows resultsnode src/cli.js ast -j --engine nativevs--engine wasmcounts