feat: add Halstead, LOC, and MI metrics to Rust native engine#159
feat: add Halstead, LOC, and MI metrics to Rust native engine#159carlos-alm merged 1 commit intomainfrom
Conversation
The native engine previously computed only cognitive, cyclomatic, and maxNesting complexity. Halstead metrics, LOC, and Maintainability Index were only available via the WASM fallback path, leaving native users with incomplete (all-zero) data for those columns. This adds full-fidelity computation of all metrics in the Rust engine: - Add HalsteadMetrics and LocMetrics NAPI structs to types.rs - Extend ComplexityMetrics with optional halstead, loc, and MI fields - Add HalsteadRules struct with per-language classification tables for all 8 supported languages (JS/TS, Python, Go, Rust, Java, C#, Ruby, PHP), mirroring the JS HALSTEAD_RULES - Add compute_all_metrics() single-pass DFS that computes complexity + Halstead + LOC + MI in one tree walk - Update all 8 extractors to call compute_all_metrics - Update normalizeNativeSymbols in parser.js to pass through new fields - Update buildComplexityMetrics precomputed branch to use actual native values instead of hardcoded zeros Impact: 21 functions changed, 56 affected
|
Claude finished @carlos-alm's task —— View job Reviewing PR: Halstead, LOC, and MI metrics to Rust native engineI'll conduct a comprehensive review following the structured analysis phases. Todo List
Phase 1: Root Cause Analysis ✅Problem Being Solved: The native Rust engine was returning placeholder zero values for Halstead, LOC, and MI metrics. When using the native parsing path, users saw all-zero metrics instead of computed values, making the native engine incomplete compared to the WASM fallback. Why This Approach: The PR implements a comprehensive solution by:
Phase 2: Configuration Change Detection ✅✅ No High-Risk Configuration Changes Detected
Phase 3: Test Integrity Assessment ✅✅ Test Structure Preserved: No test files modified, no test expectations weakened. The PR claims "All 832 JS tests pass" which indicates existing test coverage is maintained. Engine Parity Verification: The implementation shows proper fallback handling in Phase 4: Code Quality Review ✅✅ Excellent Implementation Quality Rust Implementation (
Language Coverage (
Integration (
JavaScript Normalization (
Root Cause AnalysisProblem Being Solved: Native engine returned all-zero placeholder values for Halstead, LOC, and MI metrics, making it incomplete vs WASM fallback. Critical ConcernsNone identified. This is a high-quality implementation that addresses a real functional gap. Final Recommendation
|
Greptile SummaryThis PR implements comprehensive metrics computation in the Rust native engine, replacing placeholder zeros with real Halstead, LOC, and Maintainability Index values. The implementation merges complexity and Halstead counting into a single DFS tree walk for performance, matching the existing JS behavior while eliminating redundant traversals. Key changes:
The implementation is well-structured with proper error handling, consistent formulas between JS and Rust, and comprehensive language support. Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Language Extractor] -->|calls| B[compute_all_metrics]
B --> C[Initialize State]
C --> D[Single DFS Walk]
D --> E[Complexity Counting]
D --> F[Halstead Classification]
E --> G[Cognitive/Cyclomatic/Nesting]
F --> H[Operators/Operands Maps]
D --> I[Walk Complete]
I --> J[Compute LOC Metrics]
J --> K[Text-based Line Counting]
K --> L[LOC/SLOC/Comments]
I --> M[Compute Halstead Derived]
H --> M
M --> N[Volume/Difficulty/Effort/Bugs]
I --> O[Compute Maintainability Index]
G --> O
N --> O
L --> O
O --> P[MI Score 0-100]
P --> Q[Return ComplexityMetrics]
G --> Q
N --> Q
L --> Q
P --> Q
Q --> R[JS normalizeNativeSymbols]
R --> S[buildComplexityMetrics]
S --> T[Database Insert]
Last reviewed commit: ee86fd5 |
Summary
compute_all_metrics()single-pass DFS in Rust that merges complexity + Halstead classification into one tree walk, matching the JScomputeAllMetricsbehaviorTest plan
cargo test -p codegraph-coreafter Rust toolchain is available (CI)node src/cli.js complexity -Tshows non-zero Halstead/MI columns