Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(ruby_contents, file:, max_line_length: nil, overloads_strategy: :

@max_line_length = max_line_length
@overloads_strategy = overloads_strategy
@type_translator = RBI::RBS::TypeTranslator.new #: RBI::RBS::TypeTranslator
end

# @override
Expand Down Expand Up @@ -108,11 +109,11 @@ def visit_attr(node)
name = node.arguments&.arguments&.first #: as Prism::SymbolNode
sig.params << RBI::SigParam.new(
name.slice[1..-1], #: as String
RBI::RBS::TypeTranslator.translate(attr_type),
@type_translator.translate(attr_type),
)
end

sig.return_type = RBI::RBS::TypeTranslator.translate(attr_type)
sig.return_type = @type_translator.translate(attr_type)

apply_member_annotations(comments.method_annotations, sig)

Expand Down Expand Up @@ -234,7 +235,7 @@ def apply_class_annotations(node)
"final!"
when /^@requires_ancestor: /
srb_type = ::RBS::Parser.parse_type(annotation.string.delete_prefix("@requires_ancestor: "))
rbs_type = RBI::RBS::TypeTranslator.translate(srb_type)
rbs_type = @type_translator.translate(srb_type)
"requires_ancestor { #{rbs_type} }"
else
next
Expand Down Expand Up @@ -279,12 +280,12 @@ def apply_class_annotations(node)

if type_param.upper_bound || type_param.default_type
if type_param.upper_bound
rbs_type = RBI::RBS::TypeTranslator.translate(type_param.upper_bound)
rbs_type = @type_translator.translate(type_param.upper_bound)
type_member = "#{type_member} {{ upper: #{rbs_type} }}"
end

if type_param.default_type
rbs_type = RBI::RBS::TypeTranslator.translate(type_param.default_type)
rbs_type = @type_translator.translate(type_param.default_type)
type_member = "#{type_member} {{ fixed: #{rbs_type} }}"
end
end
Expand Down Expand Up @@ -392,7 +393,7 @@ def apply_type_aliases(comments)
next unless decls.size == 1 && decls.first.is_a?(::RBS::AST::Declarations::TypeAlias)

rbs_type = decls.first
sorbet_type = RBI::RBS::TypeTranslator.translate(rbs_type.type)
sorbet_type = @type_translator.translate(rbs_type.type)

alias_name = ::RBS::TypeName.new(
namespace: rbs_type.name.namespace,
Expand Down
Loading