Skip to content

feat: Rust core engine via napi-rs (Phase 1)#8

Merged
carlos-alm merged 12 commits intomainfrom
feat/rust-core
Feb 22, 2026
Merged

feat: Rust core engine via napi-rs (Phase 1)#8
carlos-alm merged 12 commits intomainfrom
feat/rust-core

Conversation

@carlos-alm
Copy link
Copy Markdown
Contributor

Summary

Add a native Rust parsing engine via napi-rs as an optional high-performance alternative to the existing WASM pipeline. The WASM path remains the always-available baseline; the native engine activates automatically when platform binaries are installed.

Phase 1 — Rust core (napi-rs dual-engine)

  • All 11 language extractors (JS/TS/TSX, Python, Go, Rust, Java, C#, Ruby, PHP, HCL) ported to Rust with a SymbolExtractor trait
  • Rayon-based parallel file parsing
  • 6-level import resolution with confidence scoring
  • Tarjan's SCC cycle detection
  • Incremental parse tree cache for watch mode

Phase 1.2 — Unified API

  • parseFileAuto, parseFilesAuto, getActiveEngine as the single entry point in parser.js
  • Builder and watcher use the unified API — no direct native imports

Phase 1.3 — Incremental parsing

  • Native ParseTreeCache exposed via napi-rs for watch mode old-tree hints

Phase 1.4 — Native import resolution

  • resolveImportPath and computeConfidence extracted to src/resolve.js with native dispatch
  • Batch pre-resolution of all imports in a single native call

Phase 1.5 — Graceful degradation & diagnostics

  • --engine flag plumbed to watch command
  • codegraph info diagnostic command
  • CI workflows for cross-platform test matrix and native build pipeline

Changes

  • 40 files changed, ~5,500 lines added
  • New Rust crate at crates/codegraph-core/
  • New JS modules: src/native.js, src/resolve.js
  • Refactored: src/builder.js, src/parser.js, src/cli.js, src/watcher.js, src/cycles.js
  • CI: build-native.yml (4-platform matrix), ci.yml
  • Tests: engine parity, unified API, import resolution parity, build parity, incremental cache

Test plan

  • npm test — full WASM test suite passes (no native required)
  • Cross-engine parity tests pass when native binary is available
  • Build parity test confirms identical graph output from both engines
  • codegraph info reports correct engine status
  • --engine wasm forces WASM even when native is available
  • Watch mode falls back gracefully when native unavailable

🤖 Generated with Claude Code

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant