Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions lib/rbi/rbs/method_type_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,35 @@ def translate(method, type)
end
end

# @abstract
class Options
#: (?erase_generic_types: bool) -> void
def initialize(erase_generic_types: false)
@erase_generic_types = erase_generic_types
end

#: -> bool
def erase_generic_types? = @erase_generic_types
end

class HumanReadableOptions < Options
@default = new.freeze #: HumanReadableOptions
class << self
#: HumanReadableOptions
attr_reader :default
end
end

#: Sig
attr_reader :result

#: (Method) -> void
def initialize(method)
#: (Method, ?options: Options) -> void
def initialize(method, options: HumanReadableOptions.default)
@method = method
@options = options

@result = Sig.new #: Sig
@type_translator = TypeTranslator.new #: TypeTranslator
@type_translator = TypeTranslator.new(options:) #: TypeTranslator
end

#: (::RBS::MethodType) -> void
Expand Down
8 changes: 8 additions & 0 deletions lib/rbi/rbs/type_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def translate(type)
end
end

Options = MethodTypeTranslator::Options
HumanReadableOptions = MethodTypeTranslator::HumanReadableOptions

#: (?options: Options) -> void
def initialize(options: HumanReadableOptions.default)
@options = options
end

#: (rbs_type) -> Type
def translate(type)
case type
Expand Down
26 changes: 24 additions & 2 deletions rbi/rbi.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,8 @@ RBI::Public::DEFAULT = T.let(T.unsafe(nil), RBI::Public)
module RBI::RBS; end

class RBI::RBS::MethodTypeTranslator
sig { params(method: ::RBI::Method).void }
def initialize(method); end
sig { params(method: ::RBI::Method, options: ::RBI::RBS::MethodTypeTranslator::Options).void }
def initialize(method, options: T.unsafe(nil)); end

sig { returns(::RBI::Sig) }
def result; end
Expand Down Expand Up @@ -1417,7 +1417,27 @@ end

class RBI::RBS::MethodTypeTranslator::Error < ::RBI::Error; end

class RBI::RBS::MethodTypeTranslator::HumanReadableOptions < ::RBI::RBS::MethodTypeTranslator::Options
class << self
sig { returns(::RBI::RBS::MethodTypeTranslator::HumanReadableOptions) }
def default; end
end
end

class RBI::RBS::MethodTypeTranslator::Options
abstract!

sig { params(erase_generic_types: T::Boolean).void }
def initialize(erase_generic_types: T.unsafe(nil)); end

sig { returns(T::Boolean) }
def erase_generic_types?; end
end

class RBI::RBS::TypeTranslator
sig { params(options: ::RBI::RBS::MethodTypeTranslator::Options).void }
def initialize(options: T.unsafe(nil)); end

sig do
params(
type: T.any(::RBS::Types::Alias, ::RBS::Types::Bases::Any, ::RBS::Types::Bases::Bool, ::RBS::Types::Bases::Bottom, ::RBS::Types::Bases::Class, ::RBS::Types::Bases::Instance, ::RBS::Types::Bases::Nil, ::RBS::Types::Bases::Self, ::RBS::Types::Bases::Top, ::RBS::Types::Bases::Void, ::RBS::Types::ClassInstance, ::RBS::Types::ClassSingleton, ::RBS::Types::Function, ::RBS::Types::Interface, ::RBS::Types::Intersection, ::RBS::Types::Literal, ::RBS::Types::Optional, ::RBS::Types::Proc, ::RBS::Types::Record, ::RBS::Types::Tuple, ::RBS::Types::Union, ::RBS::Types::UntypedFunction, ::RBS::Types::Variable)
Expand Down Expand Up @@ -1449,6 +1469,8 @@ class RBI::RBS::TypeTranslator
end
end

RBI::RBS::TypeTranslator::HumanReadableOptions = RBI::RBS::MethodTypeTranslator::HumanReadableOptions
RBI::RBS::TypeTranslator::Options = RBI::RBS::MethodTypeTranslator::Options
RBI::RBS::TypeTranslator::RbsType = T.type_alias { T.any(::RBS::Types::Alias, ::RBS::Types::Bases::Any, ::RBS::Types::Bases::Bool, ::RBS::Types::Bases::Bottom, ::RBS::Types::Bases::Class, ::RBS::Types::Bases::Instance, ::RBS::Types::Bases::Nil, ::RBS::Types::Bases::Self, ::RBS::Types::Bases::Top, ::RBS::Types::Bases::Void, ::RBS::Types::ClassInstance, ::RBS::Types::ClassSingleton, ::RBS::Types::Function, ::RBS::Types::Interface, ::RBS::Types::Intersection, ::RBS::Types::Literal, ::RBS::Types::Optional, ::RBS::Types::Proc, ::RBS::Types::Record, ::RBS::Types::Tuple, ::RBS::Types::Union, ::RBS::Types::UntypedFunction, ::RBS::Types::Variable) }

class RBI::RBSComment < ::RBI::Comment
Expand Down
Loading