Module: TreeHaver::Backends::Rust

Defined in:
lib/tree_haver/backends/rust.rb

Overview

Note:

This backend works on MRI Ruby. JRuby/TruffleRuby support is unknown.

Rust backend using the tree_stump gem

This backend wraps the tree_stump gem, which provides Ruby bindings to tree-sitter written in Rust. It offers native performance with Rust’s safety guarantees and includes precompiled binaries for common platforms.

tree_stump supports incremental parsing and the Query API, making it suitable for editor/IDE use cases where performance is critical.

See Also:

Defined Under Namespace

Classes: Language, Parser

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tree_haver/backends/rust.rb', line 30

def available?
  return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable
  @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable
  begin
    require "tree_stump"

    @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable
  rescue LoadError
    @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable
  end
  @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable
end

.capabilitiesHash{Symbol => Object}

Get capabilities supported by this backend

Examples:

TreeHaver::Backends::Rust.capabilities
# => { backend: :rust, query: true, bytes_field: true, incremental: false }

Returns:

  • (Hash{Symbol => Object})

    capability map



58
59
60
61
62
63
64
65
66
# File 'lib/tree_haver/backends/rust.rb', line 58

def capabilities
  return {} unless available?
  {
    backend: :rust,
    query: true,
    bytes_field: true,
    incremental: false,  # TreeStump doesn't currently expose incremental parsing to Ruby
  }
end

.reset!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Reset the load state (primarily for testing)



47
48
49
50
# File 'lib/tree_haver/backends/rust.rb', line 47

def reset!
  @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable
  @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable
end