Add Ruby extraction via Prism, not tree-sitter - #116
Open
emmahyde wants to merge 1 commit into
Open
Conversation
mex's code graph only indexed frontend TS/JS/Python/Rust; Ruby files were silently skipped (no extractor, no grammar), so `mex graph query` returned TARGET_NOT_FOUND for every Rails symbol. Rather than vendor the community tree-sitter-ruby grammar, use @ruby/prism — Ruby core's own parser (the one CRuby 3.3+ ships) — which is more semantically accurate for Ruby. Prism's typed AST has no tree-sitter node shape, so `rubyExtractor.extract()` ignores the passed `tree` and re-parses `source` with Prism directly; `prism-runtime.ts` is Ruby's parallel loader alongside `grammars.ts`'s tree-sitter loader. Verified against real groot Rails files (STI phase base class, service objects) with no crashes.
Author
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.
What
Adds a Ruby language extractor so
mex graphindexes.rbfiles. Ruby was previously silently skipped — no grammar, no extractor — somex graph query where-defined <RailsSymbol>returnedTARGET_NOT_FOUNDfor every Ruby symbol on a real Rails codebase.Why Prism, not tree-sitter
Rather than vendor the community
tree-sitter-rubygrammar (the pattern every other language in this repo follows), this uses@ruby/prism— Ruby core's own parser, the one CRuby 3.3+ ships. It's more semantically accurate for Ruby than a third-party tree-sitter grammar, and it's maintained by the Ruby core team.Prism's typed AST has no tree-sitter node shape to adapt into, so this needed two small, deliberately isolated deviations from the standard extractor path (documented in
docs/extractors.mdunder "Vendored Grammars > Ruby"):src/graph/extraction/prism-runtime.ts— Ruby's parallel loader togrammars.ts's tree-sitter loader (Prism has no relationship toweb-tree-sitter).rubyExtractor.extract()ignores the passedtree: TSTreeparameter entirely and re-parsessourcewith Prism directly.grammars.ts#parse()still returns a placeholderTSTreefor Ruby soextractFile's genericif (!tree) return nullgate behaves identically across every language — no changes to the frozenLanguageExtractorinterface, node identity scheme, or SQLite schema.Coverage
rubyExtractor(src/graph/extraction/languages/ruby.ts) covers: modules, classes (with superclassextendsedges), instance and singleton (def self.x) methods, module/class-scoped constants, mixins (include/extend/prepend→implements),require/require_relative→imports,.new→instantiates, and general methodcalls.Fixture (
src/graph/__tests__/fixtures/sample.rb) and focused tests (src/graph/__tests__/extractor-ruby.test.ts, 7 tests) follow the existingextractor.test.ts/sample.tspattern.Verification
npx tsc --noEmit— clean.npx vitest run— full suite passes except one pre-existing, unrelated failure intest/tui.test.ts(confirmed viagit stash/git stash popbisection: identical failure with zero of this PR's changes present).npm run build— clean,.wasm/schema assets copy as expected.where-defined/who-calls/graph scopenow resolve Ruby symbols end-to-end, including cross-file call chains and STI overrides.Docs
Updated
docs/extractors.md(Vendored Grammars > Ruby, with an explicit deviation note) anddocs/code-graph-support.md(added the Ruby row to the support table).