Class: Docscribe::Types::RBS::Provider

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(sig_dirs:, collapse_generics: false) ⇒ Object

Parameters:

  • sig_dirs (Array<String>)

    directories containing ‘.rbs` files

  • collapse_generics (Boolean) (defaults to: false)

    whether generic container types should be simplified during formatting



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.

Parameters:

  • container (String)

    e.g. “MyModule::MyClass”

  • scope (Symbol)

    :instance or :class

  • name (Symbol, String)

    method name

Returns:

Raises:

  • (::RBS::BaseError)
  • (StandardError)


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.message}")
  nil
rescue StandardError => e
  warn_once(
    'Docscribe: RBS integration failed (falling back to inference): ' \
    "#{e.class}: #{e.message}\nFeel free to open an issue on github."
  )
  nil
end