Skip to content

Conversation

@pboling
Copy link
Contributor

@pboling pboling commented Jan 31, 2026

This PR is tracking changes in my fork, where I am working on two things:

  • Update to tree-sitter LANGUAGE_VERSION 15
  • Update rb-sys and magnus to support building against Ruby 4.1.0+1 (current HEAD)

Refs:

Includes (on top of):

Update tree_stump to support the tree-sitter Rust crate 0.26.x,
enabling grammars with LANGUAGE_VERSION 15 to be loaded.

Changes:
- Replace Language::version() with Language::abi_version()
- Remove deprecated parser timeout/cancellation APIs
- Handle Parser::language() returning Option<LanguageRef>
- Convert usize to u32 for Node::child() and Node::named_child()
- Use streaming_iterator for QueryMatches iteration
- Update Cargo.toml to tree-sitter = "0.26.3"
- Add streaming-iterator = "0.1" dependency

BREAKING CHANGE: Parser#timeout_micros method is removed (deprecated
in 0.25, removed upstream in 0.26). Parser#language now returns nil
after setting a language due to API changes in the Rust crate.

Closes joker1007#16
Consolidate tree-sitter environment setup using the kettle-rb/ts-grammar-action
composite action instead of separate steps for Java, tree-sitter, and Rust.

Before:
- actions/setup-java@v5 (conditional for TruffleRuby/JRuby)
- tree-sitter/setup-action@v2 (library and CLI)
- actions-rust-lang/setup-rust-toolchain@v1 (Rust for tree_stump)

After:
- kettle-rb/ts-grammar-action@v1 (all-in-one)
  - install-cli: true
  - install-lib: true
  - setup-rust: true (required for tree_stump Rust extension)
  - setup-java: conditional (for TruffleRuby/JRuby)

This reduces workflow complexity and ensures consistent tree-sitter
environment setup across kettle-rb projects.

Closes joker1007#17
- usize can be larger than u32.
- On conversion failure (index > 4,294,967,295)
  - Now returns None
  - Previously truncated the value
- Remove unsound unsafe transmute in Parser::language() that extended
  LanguageRef lifetime from borrowed scope to 'static. The safety comment
  claimed languages outlive parsers, but this wasn't enforced by the type
  system and could lead to use-after-free.

- Redesign Parser to store language_name and look up the language directly
  from the global LANG_LANGUAGES map in build_query(), keeping proper
  lifetime bounds tied to the lock guard.
Rust source changes (ext/tree_stump/src/*.rs):

- Fix compilation error in parser.rs by changing Query::new to accept
  &tree_sitter::Language instead of &tree_sitter::LanguageRef
- Replace deprecated magnus::exception::runtime_error() calls with
  build_error() helper throughout lib.rs, query.rs, and tree.rs
- Replace deprecated magnus::exception::type_error() with
  ruby.exception_type_error() in query.rs
- Fix deprecated into_symbol() -> into_symbol_with(&ruby) in query.rs
- Fix deprecated into_value() -> into_value_with(ruby) in query.rs
- Add #[allow(deprecated)] for unavoidable fallback case in util.rs
- Fix lifetime elision warnings by adding explicit <'_> lifetime
  parameters to Node and TreeCursor return types in tree.rs

Spec changes:

- Update spec_helper.rb to use TREE_SITTER_RUBY_PATH env var for
  grammar path, falling back to local path for CI
- Add is_missing? and missing? method tests for Node class
- Add helper methods find_missing_nodes and check_all_nodes for
  tree traversal in tests
- Change gemspec extensions from Cargo.toml to extconf.rb to use rb_sys/mkmf
- Add rb_sys ~> 0.9.119 as runtime dependency (required by extconf.rb)
- Add CI build verification steps to ensure extension compiles before tests
- Add Rust version verification and explicit compile step in workflow
- Improve error diagnostics for extension build failures

Fixes issue where extension built successfully but .so file wasn't found
in CI due to RubyGems using native Cargo builder instead of rb_sys.
# Conflicts:
#	.github/workflows/rspec.yml
@pboling pboling changed the title Tracking PR Tracking PR - Ruby HEAD compat Jan 31, 2026
@pboling pboling changed the title Tracking PR - Ruby HEAD compat Tracking PR - Ruby HEAD & tree-sitter v0.26 compat Jan 31, 2026
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