Module: Rbs::Merge::Backends::RbsBackend
- Defined in:
- lib/rbs/merge/backends/rbs_backend.rb
Overview
This backend only works on MRI Ruby (the RBS gem has C extensions)
This backend only parses RBS type signature files
RBS gem backend using Ruby’s official RBS parser
This backend wraps the RBS gem, Ruby’s official type signature parser.
Unlike tree-sitter backends which are language-agnostic runtime parsers,
the RBS gem is specifically designed for parsing RBS type signature files.
The RBS gem provides:
- Rich AST with declaration types (Class, Module, Interface, TypeAlias, etc.)
- Member types (MethodDefinition, Alias, AttrReader, etc.)
- Location information for all nodes
- Full RBS language support including generics, type aliases, etc.
Defined Under Namespace
Classes: Language, Node, Parser, Tree
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if the RBS backend is available.
-
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend.
-
.reset! ⇒ void
private
Reset the load state (primarily for testing).
Class Method Details
.available? ⇒ Boolean
Check if the RBS backend is available
Attempts to require rbs on first call and caches the result.
The RBS gem only works on MRI Ruby (C extension).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rbs/merge/backends/rbs_backend.rb', line 50 def available? return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable begin require "rbs" # Verify it can actually parse - just requiring isn't enough buffer = ::RBS::Buffer.new(name: "test.rbs", content: "class Foo end") ::RBS::Parser.parse_signature(buffer) @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable rescue LoadError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable rescue StandardError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable end |
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rbs/merge/backends/rbs_backend.rb', line 82 def capabilities return {} unless available? { backend: :rbs, query: false, # RBS doesn't have tree-sitter-style queries bytes_field: true, # RBS provides byte offsets via Location incremental: false, # RBS doesn't support incremental parsing pure_ruby: false, # RBS gem has native C extension rbs_only: true, # RBS gem only parses RBS type signatures error_tolerant: false, # RBS parser raises on errors mri_only: true, # RBS gem C extension only works on MRI } 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)
71 72 73 74 |
# File 'lib/rbs/merge/backends/rbs_backend.rb', line 71 def reset! @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end |