Class: Docscribe::Types::RBS::Provider
- Inherits:
-
Object
- Object
- Docscribe::Types::RBS::Provider
- Defined in:
- lib/docscribe/types/rbs/provider.rb
Overview
Resolve method signatures from ‘.rbs` files using the official RBS environment and definition builder APIs.
The provider returns Docscribe’s normalized signature model so the rest of the pipeline can stay independent of the underlying signature source.
Instance Method Summary collapse
- #initialize(sig_dirs:, collapse_generics: false) ⇒ Object constructor
-
#signature_for(container:, scope:, name:) ⇒ Docscribe::Types::MethodSignature?
Look up a normalized method signature from loaded RBS definitions.
Constructor Details
#initialize(sig_dirs:, collapse_generics: false) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/docscribe/types/rbs/provider.rb', line 21 def initialize(sig_dirs:, collapse_generics: false) require 'rbs' @sig_dirs = Array(sig_dirs).map(&:to_s) @collapse_generics = !!collapse_generics @env = nil @builder = nil @warned = false end |
Instance Method Details
#signature_for(container:, scope:, name:) ⇒ Docscribe::Types::MethodSignature?
Look up a normalized method signature from loaded RBS definitions.
Returns nil when the method cannot be resolved or when RBS lookup fails.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/docscribe/types/rbs/provider.rb', line 40 def signature_for(container:, scope:, name:) load_env! definition = definition_for(container: container, scope: scope) method_def = definition.methods[name.to_sym] return nil unless method_def method_type = method_def.method_types.first return nil unless method_type func = method_type.type build_signature(func) rescue ::RBS::BaseError => e warn_once("Docscribe: RBS error: #{e.class}: #{e.}") nil rescue StandardError => e warn_once( 'Docscribe: RBS integration failed (falling back to inference): ' \ "#{e.class}: #{e.}\nFeel free to open an issue on github." ) nil end |