rbi 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rbi/model.rb +79 -2
- data/lib/rbi/parser.rb +43 -8
- data/lib/rbi/printer.rb +15 -2
- data/lib/rbi/rbs/method_type_translator.rb +1 -1
- data/lib/rbi/rbs/type_translator.rb +7 -4
- data/lib/rbi/rbs_printer.rb +78 -100
- data/lib/rbi/rewriters/add_sig_templates.rb +6 -1
- data/lib/rbi/rewriters/attr_to_methods.rb +1 -0
- data/lib/rbi/rewriters/merge_trees.rb +33 -6
- data/lib/rbi/type.rb +12 -12
- data/lib/rbi/type_parser.rb +4 -6
- data/lib/rbi/version.rb +1 -1
- data/lib/rbi/visitor.rb +10 -0
- data/rbi/rbi.rbi +161 -38
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7abed145bf2c620d24e9b6cd69c6b58e4a1a88230f1fa304018621098f13c89b
|
|
4
|
+
data.tar.gz: 24c00005fa963db2dcec897a7412cb8e953c3f03007e8ab7f986e66a4927ffad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f314b0af5386993a597e17f5276ff960cd200b85fa03263ee3d957026db549ca0282dbc0c351e0719e0f472d37feb0ff976f521dc6266c0e9b5f57730948bafb
|
|
7
|
+
data.tar.gz: bcb533b21bb1850002f6c7bba3bf661586f95e192e5f31b656fdab4992f5c0cd4851b160b37e1cd3ba2296cae630c00bf017d23c613e0c82aad5bc854ebd88d1
|
data/Gemfile
CHANGED
|
@@ -10,7 +10,7 @@ group(:development, :test) do
|
|
|
10
10
|
gem("minitest")
|
|
11
11
|
gem("minitest-reporters")
|
|
12
12
|
gem("rake", "~> 13.4")
|
|
13
|
-
gem("rubocop", "~> 1.
|
|
13
|
+
gem("rubocop", "~> 1.92", require: false)
|
|
14
14
|
gem("rubocop-shopify", require: false)
|
|
15
15
|
gem("rubocop-sorbet", require: false)
|
|
16
16
|
gem("sorbet", ">= 0.5.9204", require: false)
|
data/lib/rbi/model.rb
CHANGED
|
@@ -542,14 +542,25 @@ module RBI
|
|
|
542
542
|
params << KwRestParam.new(name)
|
|
543
543
|
end
|
|
544
544
|
|
|
545
|
+
#: -> void
|
|
546
|
+
def add_no_kw_param
|
|
547
|
+
params << NoKwParam.new
|
|
548
|
+
end
|
|
549
|
+
|
|
545
550
|
#: (String name) -> void
|
|
546
551
|
def add_block_param(name)
|
|
547
552
|
params << BlockParam.new(name)
|
|
548
553
|
end
|
|
549
554
|
|
|
555
|
+
#: -> void
|
|
556
|
+
def add_forwarding_param
|
|
557
|
+
params << ForwardingParam.new
|
|
558
|
+
end
|
|
559
|
+
|
|
550
560
|
#: (
|
|
551
561
|
#| ?params: Array[SigParam]?,
|
|
552
562
|
#| ?return_type: (String | Type),
|
|
563
|
+
#| ?bind_type: (String | Type)?,
|
|
553
564
|
#| ?is_abstract: bool,
|
|
554
565
|
#| ?is_override: bool,
|
|
555
566
|
#| ?is_overridable: bool,
|
|
@@ -559,6 +570,7 @@ module RBI
|
|
|
559
570
|
def add_sig(
|
|
560
571
|
params: [],
|
|
561
572
|
return_type: "void",
|
|
573
|
+
bind_type: nil,
|
|
562
574
|
is_abstract: false,
|
|
563
575
|
is_override: false,
|
|
564
576
|
is_overridable: false,
|
|
@@ -570,6 +582,7 @@ module RBI
|
|
|
570
582
|
sig = Sig.new(
|
|
571
583
|
params: params,
|
|
572
584
|
return_type: return_type,
|
|
585
|
+
bind_type: bind_type,
|
|
573
586
|
is_abstract: is_abstract,
|
|
574
587
|
is_override: is_override,
|
|
575
588
|
is_overridable: is_overridable,
|
|
@@ -607,7 +620,7 @@ module RBI
|
|
|
607
620
|
#: -> String?
|
|
608
621
|
def name
|
|
609
622
|
case self
|
|
610
|
-
when ReqParam, OptParam, KwParam, KwOptParam, RestParam, KwRestParam, BlockParam
|
|
623
|
+
when ReqParam, OptParam, KwParam, KwOptParam, RestParam, KwRestParam, BlockParam, ForwardingParam
|
|
611
624
|
name
|
|
612
625
|
end
|
|
613
626
|
end
|
|
@@ -807,6 +820,31 @@ module RBI
|
|
|
807
820
|
end
|
|
808
821
|
end
|
|
809
822
|
|
|
823
|
+
class NoKwParam < Param
|
|
824
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (NoKwParam node) -> void } -> void
|
|
825
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
826
|
+
super(loc: loc, comments: comments)
|
|
827
|
+
block&.call(self)
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
# @override
|
|
831
|
+
#: -> String
|
|
832
|
+
def to_s
|
|
833
|
+
"**nil"
|
|
834
|
+
end
|
|
835
|
+
|
|
836
|
+
# @override
|
|
837
|
+
#: -> bool
|
|
838
|
+
def anonymous?
|
|
839
|
+
false
|
|
840
|
+
end
|
|
841
|
+
|
|
842
|
+
#: (Object? other) -> bool
|
|
843
|
+
def ==(other)
|
|
844
|
+
NoKwParam === other
|
|
845
|
+
end
|
|
846
|
+
end
|
|
847
|
+
|
|
810
848
|
class BlockParam < Param
|
|
811
849
|
# @override
|
|
812
850
|
#: String?
|
|
@@ -837,6 +875,38 @@ module RBI
|
|
|
837
875
|
end
|
|
838
876
|
end
|
|
839
877
|
|
|
878
|
+
# The `...` in `def m(...)`
|
|
879
|
+
class ForwardingParam < Param
|
|
880
|
+
# @override
|
|
881
|
+
#: -> nil
|
|
882
|
+
def name
|
|
883
|
+
nil
|
|
884
|
+
end
|
|
885
|
+
|
|
886
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (ForwardingParam node) -> void } -> void
|
|
887
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
888
|
+
super(loc: loc, comments: comments)
|
|
889
|
+
block&.call(self)
|
|
890
|
+
end
|
|
891
|
+
|
|
892
|
+
# @override
|
|
893
|
+
#: -> String
|
|
894
|
+
def to_s
|
|
895
|
+
"..."
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
# @override
|
|
899
|
+
#: -> bool
|
|
900
|
+
def anonymous?
|
|
901
|
+
false
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
#: (Object? other) -> bool
|
|
905
|
+
def ==(other)
|
|
906
|
+
ForwardingParam === other
|
|
907
|
+
end
|
|
908
|
+
end
|
|
909
|
+
|
|
840
910
|
# Mixins
|
|
841
911
|
|
|
842
912
|
# @abstract
|
|
@@ -1028,6 +1098,9 @@ module RBI
|
|
|
1028
1098
|
#: (Type | String)
|
|
1029
1099
|
attr_accessor :return_type
|
|
1030
1100
|
|
|
1101
|
+
#: (Type | String)?
|
|
1102
|
+
attr_accessor :bind_type
|
|
1103
|
+
|
|
1031
1104
|
#: bool
|
|
1032
1105
|
attr_accessor :is_abstract
|
|
1033
1106
|
|
|
@@ -1065,6 +1138,7 @@ module RBI
|
|
|
1065
1138
|
#: (
|
|
1066
1139
|
#| ?params: Array[SigParam]?,
|
|
1067
1140
|
#| ?return_type: (Type | String),
|
|
1141
|
+
#| ?bind_type: (Type | String)?,
|
|
1068
1142
|
#| ?is_abstract: bool,
|
|
1069
1143
|
#| ?is_override: bool,
|
|
1070
1144
|
#| ?is_overridable: bool,
|
|
@@ -1080,6 +1154,7 @@ module RBI
|
|
|
1080
1154
|
def initialize(
|
|
1081
1155
|
params: nil,
|
|
1082
1156
|
return_type: "void",
|
|
1157
|
+
bind_type: nil,
|
|
1083
1158
|
is_abstract: false,
|
|
1084
1159
|
is_override: false,
|
|
1085
1160
|
is_overridable: false,
|
|
@@ -1096,6 +1171,7 @@ module RBI
|
|
|
1096
1171
|
super(loc: loc, comments: comments)
|
|
1097
1172
|
@params = params #: Array[SigParam]?
|
|
1098
1173
|
@return_type = return_type
|
|
1174
|
+
@bind_type = bind_type
|
|
1099
1175
|
@is_abstract = is_abstract
|
|
1100
1176
|
@is_override = is_override
|
|
1101
1177
|
@is_overridable = is_overridable
|
|
@@ -1122,7 +1198,8 @@ module RBI
|
|
|
1122
1198
|
def ==(other)
|
|
1123
1199
|
return false unless other.is_a?(Sig)
|
|
1124
1200
|
|
|
1125
|
-
params == other.params && return_type.to_s == other.return_type.to_s &&
|
|
1201
|
+
params == other.params && return_type.to_s == other.return_type.to_s &&
|
|
1202
|
+
bind_type&.to_s == other.bind_type&.to_s && is_abstract == other.is_abstract &&
|
|
1126
1203
|
is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
|
|
1127
1204
|
without_runtime == other.without_runtime && type_params == other.type_params && checked == other.checked
|
|
1128
1205
|
end
|
data/lib/rbi/parser.rb
CHANGED
|
@@ -139,6 +139,21 @@ module RBI
|
|
|
139
139
|
node_string(node) #: as !nil
|
|
140
140
|
end
|
|
141
141
|
|
|
142
|
+
#: (Prism::Node node) -> String
|
|
143
|
+
def type_string(node)
|
|
144
|
+
type = node_string!(node)
|
|
145
|
+
braceless_shape?(node) ? "{#{type}}" : type
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
#: (Prism::Node node) -> bool
|
|
149
|
+
def braceless_shape?(node)
|
|
150
|
+
return false unless node.is_a?(Prism::KeywordHashNode)
|
|
151
|
+
|
|
152
|
+
node.elements.all? do |element|
|
|
153
|
+
element.is_a?(Prism::AssocNode) && element.operator_loc
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
142
157
|
#: (Prism::Node node) -> Prism::Location
|
|
143
158
|
def adjust_prism_location_for_heredoc(node)
|
|
144
159
|
visitor = HeredocLocationVisitor.new(
|
|
@@ -537,15 +552,14 @@ module RBI
|
|
|
537
552
|
# Collect all the remaining comments within a node
|
|
538
553
|
#: (Prism::Node node) -> void
|
|
539
554
|
def collect_dangling_comments(node)
|
|
540
|
-
first_line = node.location.start_line
|
|
541
555
|
last_line = node.location.end_line
|
|
542
556
|
|
|
543
557
|
last_node_last_line = node.child_nodes.last&.location&.end_line
|
|
558
|
+
first_line = last_node_last_line ? last_node_last_line + 1 : node.location.start_line
|
|
544
559
|
|
|
545
560
|
first_line.upto(last_line) do |line|
|
|
546
561
|
comment = @comments_by_line[line]
|
|
547
562
|
next unless comment
|
|
548
|
-
break if last_node_last_line && line <= last_node_last_line
|
|
549
563
|
|
|
550
564
|
current_scope << parse_comment(comment)
|
|
551
565
|
@comments_by_line.delete(line)
|
|
@@ -743,6 +757,11 @@ module RBI
|
|
|
743
757
|
loc: node_loc(param),
|
|
744
758
|
comments: node_comments(param),
|
|
745
759
|
)
|
|
760
|
+
when Prism::NoKeywordsParameterNode
|
|
761
|
+
NoKwParam.new(
|
|
762
|
+
loc: node_loc(param),
|
|
763
|
+
comments: node_comments(param),
|
|
764
|
+
)
|
|
746
765
|
when Prism::KeywordRestParameterNode
|
|
747
766
|
KwRestParam.new(
|
|
748
767
|
param.name&.to_s,
|
|
@@ -755,6 +774,11 @@ module RBI
|
|
|
755
774
|
loc: node_loc(param),
|
|
756
775
|
comments: node_comments(param),
|
|
757
776
|
)
|
|
777
|
+
when Prism::ForwardingParameterNode
|
|
778
|
+
ForwardingParam.new(
|
|
779
|
+
loc: node_loc(param),
|
|
780
|
+
comments: node_comments(param),
|
|
781
|
+
)
|
|
758
782
|
else
|
|
759
783
|
raise ParseError.new("Unexpected parameter node `#{param.class}`", node_loc(param))
|
|
760
784
|
end
|
|
@@ -828,7 +852,7 @@ module RBI
|
|
|
828
852
|
return unless type_arg
|
|
829
853
|
|
|
830
854
|
name = node_string!(name_arg).delete_prefix(":")
|
|
831
|
-
type =
|
|
855
|
+
type = type_string(type_arg)
|
|
832
856
|
loc = node_loc(send)
|
|
833
857
|
comments = node_comments(send)
|
|
834
858
|
default_value = nil #: String?
|
|
@@ -936,6 +960,9 @@ module RBI
|
|
|
936
960
|
@current.is_final = node_string(arg) == ":final"
|
|
937
961
|
end
|
|
938
962
|
end
|
|
963
|
+
when "bind"
|
|
964
|
+
bind_type = sig_type_argument(node)
|
|
965
|
+
@current.bind_type = bind_type if bind_type
|
|
939
966
|
when "abstract"
|
|
940
967
|
@current.is_abstract = true
|
|
941
968
|
when "checked"
|
|
@@ -953,11 +980,8 @@ module RBI
|
|
|
953
980
|
when "params"
|
|
954
981
|
visit(node.arguments)
|
|
955
982
|
when "returns"
|
|
956
|
-
|
|
957
|
-
if
|
|
958
|
-
first = args.arguments.first
|
|
959
|
-
@current.return_type = node_string!(first) if first
|
|
960
|
-
end
|
|
983
|
+
return_type = sig_type_argument(node)
|
|
984
|
+
@current.return_type = return_type if return_type
|
|
961
985
|
when "type_parameters"
|
|
962
986
|
args = node.arguments
|
|
963
987
|
if args.is_a?(Prism::ArgumentsNode)
|
|
@@ -982,6 +1006,17 @@ module RBI
|
|
|
982
1006
|
)
|
|
983
1007
|
end
|
|
984
1008
|
|
|
1009
|
+
#: (Prism::CallNode node) -> String?
|
|
1010
|
+
def sig_type_argument(node)
|
|
1011
|
+
args = node.arguments
|
|
1012
|
+
return unless args.is_a?(Prism::ArgumentsNode)
|
|
1013
|
+
|
|
1014
|
+
type_node = args.arguments.first
|
|
1015
|
+
return unless type_node
|
|
1016
|
+
|
|
1017
|
+
type_string(type_node)
|
|
1018
|
+
end
|
|
1019
|
+
|
|
985
1020
|
#: (Prism::Node node) -> String
|
|
986
1021
|
def sig_param_name(node)
|
|
987
1022
|
case node
|
data/lib/rbi/printer.rb
CHANGED
|
@@ -6,7 +6,7 @@ module RBI
|
|
|
6
6
|
|
|
7
7
|
class Printer < Visitor
|
|
8
8
|
# Pre-computed indentation strings to avoid allocating " " * indent on every line.
|
|
9
|
-
MAX_CACHED_INDENT = 50
|
|
9
|
+
MAX_CACHED_INDENT = 50
|
|
10
10
|
INDENT_CACHE = Array.new(MAX_CACHED_INDENT + 1) { |i| (" " * i).freeze }.freeze #: Array[String]
|
|
11
11
|
|
|
12
12
|
#: bool
|
|
@@ -396,12 +396,24 @@ module RBI
|
|
|
396
396
|
self.print(node.to_s)
|
|
397
397
|
end
|
|
398
398
|
|
|
399
|
+
# @override
|
|
400
|
+
#: (NoKwParam node) -> void
|
|
401
|
+
def visit_no_kw_param(node)
|
|
402
|
+
self.print(node.to_s)
|
|
403
|
+
end
|
|
404
|
+
|
|
399
405
|
# @override
|
|
400
406
|
#: (BlockParam node) -> void
|
|
401
407
|
def visit_block_param(node)
|
|
402
408
|
self.print(node.to_s)
|
|
403
409
|
end
|
|
404
410
|
|
|
411
|
+
# @override
|
|
412
|
+
#: (ForwardingParam node) -> void
|
|
413
|
+
def visit_forwarding_param(node)
|
|
414
|
+
self.print(node.to_s)
|
|
415
|
+
end
|
|
416
|
+
|
|
405
417
|
# @override
|
|
406
418
|
#: (Include node) -> void
|
|
407
419
|
def visit_include(node)
|
|
@@ -829,7 +841,7 @@ module RBI
|
|
|
829
841
|
|
|
830
842
|
#: (Sig node) -> Array[String]
|
|
831
843
|
def sig_modifiers(node)
|
|
832
|
-
return EMPTY_MODIFIERS unless node.is_abstract || node.is_override || node.is_overridable ||
|
|
844
|
+
return EMPTY_MODIFIERS unless node.is_abstract || node.is_override || node.is_overridable || node.bind_type ||
|
|
833
845
|
node.type_params? || node.checked
|
|
834
846
|
|
|
835
847
|
modifiers = [] #: Array[String]
|
|
@@ -846,6 +858,7 @@ module RBI
|
|
|
846
858
|
end
|
|
847
859
|
|
|
848
860
|
modifiers << "overridable" if node.is_overridable
|
|
861
|
+
modifiers << "bind(#{node.bind_type})" if node.bind_type
|
|
849
862
|
if node.type_params?
|
|
850
863
|
modifiers << "type_parameters(#{node.type_params.map { |type| ":#{type}" }.join(", ")})"
|
|
851
864
|
end
|
|
@@ -66,9 +66,12 @@ module RBI
|
|
|
66
66
|
when ::RBS::Types::Bases::Void
|
|
67
67
|
Type.void
|
|
68
68
|
when ::RBS::Types::ClassSingleton
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
type_parameters = if @options.erase_generic_types
|
|
70
|
+
[]
|
|
71
|
+
else
|
|
72
|
+
type.args.map { |type_arg| translate(type_arg) }
|
|
73
|
+
end
|
|
74
|
+
Type.class_of(Type.simple(type.name.to_s), *type_parameters)
|
|
72
75
|
when ::RBS::Types::ClassInstance
|
|
73
76
|
translate_class_instance(type)
|
|
74
77
|
when ::RBS::Types::Function
|
|
@@ -203,7 +206,7 @@ module RBI
|
|
|
203
206
|
"Module",
|
|
204
207
|
"Set",
|
|
205
208
|
"Range",
|
|
206
|
-
].freeze
|
|
209
|
+
].freeze
|
|
207
210
|
|
|
208
211
|
GENERIC_TYPE_TO_SORBET_GENERIC_TYPE = RUNTIME_GENERIC_TYPES.flat_map do |type|
|
|
209
212
|
[[type, "::T::#{type}"], ["::#{type}", "::T::#{type}"]]
|
data/lib/rbi/rbs_printer.rb
CHANGED
|
@@ -411,75 +411,75 @@ module RBI
|
|
|
411
411
|
new_out = StringIO.new
|
|
412
412
|
|
|
413
413
|
@out = new_out
|
|
414
|
-
|
|
414
|
+
print_method_sig_content(node, sig, multiline: false)
|
|
415
415
|
@out = old_out
|
|
416
416
|
|
|
417
417
|
max_line_length = @max_line_length
|
|
418
418
|
if @force_multiline_signatures || (max_line_length && new_out.string.size > max_line_length)
|
|
419
|
-
|
|
419
|
+
print_method_sig_content(node, sig, multiline: true)
|
|
420
420
|
else
|
|
421
421
|
print(new_out.string)
|
|
422
422
|
end
|
|
423
423
|
end
|
|
424
424
|
|
|
425
|
-
#: (RBI::Method node, Sig sig) -> void
|
|
426
|
-
def
|
|
425
|
+
#: (RBI::Method node, Sig sig, multiline: bool) -> void
|
|
426
|
+
def print_method_sig_content(node, sig, multiline:)
|
|
427
427
|
unless sig.type_params.empty?
|
|
428
428
|
print("[#{sig.type_params.join(", ")}] ")
|
|
429
429
|
end
|
|
430
430
|
|
|
431
|
-
|
|
431
|
+
no_kw_params, method_params = node.params.partition { |param| param.is_a?(NoKwParam) }
|
|
432
|
+
raise Error, "Multiple no-keywords parameters found" if no_kw_params.size > 1
|
|
433
|
+
raise Error, "Arity mismatch between method and signature" if sig.params.size != method_params.size
|
|
432
434
|
|
|
433
|
-
|
|
435
|
+
params = sig.params.zip(method_params) #: Array[[SigParam?, Param?]]
|
|
436
|
+
block_params, params = params.partition do |_sig_param, method_param|
|
|
434
437
|
method_param.is_a?(BlockParam)
|
|
435
438
|
end
|
|
436
439
|
|
|
437
440
|
raise Error, "Multiple block parameters found" if block_params.size > 1
|
|
438
441
|
|
|
439
|
-
|
|
442
|
+
no_kw_param = no_kw_params.first
|
|
443
|
+
params << [nil, no_kw_param] if no_kw_param
|
|
440
444
|
|
|
441
445
|
unless params.empty?
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
method_param, #: as !nil
|
|
448
|
-
)
|
|
449
|
-
end
|
|
450
|
-
print(") ")
|
|
451
|
-
end
|
|
452
|
-
if (sig_param = block_param&.first)
|
|
453
|
-
block_type = sig_param.type
|
|
454
|
-
block_type = Type.parse_string(block_type) if block_type.is_a?(String)
|
|
455
|
-
|
|
456
|
-
block_is_nilable = false
|
|
457
|
-
if block_type.is_a?(Type::Nilable)
|
|
458
|
-
block_is_nilable = true
|
|
459
|
-
block_type = block_type.type
|
|
446
|
+
if multiline
|
|
447
|
+
printl("(")
|
|
448
|
+
indent
|
|
449
|
+
else
|
|
450
|
+
print("(")
|
|
460
451
|
end
|
|
461
452
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
453
|
+
params.each_with_index do |(sig_param, method_param), index|
|
|
454
|
+
if multiline
|
|
455
|
+
printt
|
|
456
|
+
elsif index > 0
|
|
457
|
+
print(", ")
|
|
458
|
+
end
|
|
459
|
+
if method_param.is_a?(NoKwParam)
|
|
460
|
+
visit(method_param)
|
|
461
|
+
else
|
|
462
|
+
print_sig_param(
|
|
463
|
+
sig_param, #: as !nil
|
|
464
|
+
method_param, #: as !nil
|
|
465
|
+
)
|
|
466
|
+
end
|
|
467
|
+
if multiline
|
|
468
|
+
print(",") if index < params.size - 1
|
|
469
|
+
printn
|
|
470
|
+
end
|
|
472
471
|
end
|
|
473
472
|
|
|
474
|
-
if
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
print("?{ #{type_string} } ")
|
|
473
|
+
if multiline
|
|
474
|
+
dedent
|
|
475
|
+
printt(") ")
|
|
478
476
|
else
|
|
479
|
-
print("
|
|
477
|
+
print(") ")
|
|
480
478
|
end
|
|
481
479
|
end
|
|
482
480
|
|
|
481
|
+
print_method_sig_block(block_params.first&.first)
|
|
482
|
+
|
|
483
483
|
type = parse_type(sig.return_type)
|
|
484
484
|
print("-> #{type.rbs_string}")
|
|
485
485
|
|
|
@@ -487,73 +487,36 @@ module RBI
|
|
|
487
487
|
print(" # #{loc}") if loc && print_locs
|
|
488
488
|
end
|
|
489
489
|
|
|
490
|
-
#: (
|
|
491
|
-
def
|
|
492
|
-
unless
|
|
493
|
-
print("[#{sig.type_params.join(", ")}] ")
|
|
494
|
-
end
|
|
490
|
+
#: (SigParam? sig_param) -> void
|
|
491
|
+
def print_method_sig_block(sig_param)
|
|
492
|
+
return unless sig_param
|
|
495
493
|
|
|
496
|
-
|
|
494
|
+
block_type = sig_param.type
|
|
495
|
+
block_type = Type.parse_string(block_type) if block_type.is_a?(String)
|
|
497
496
|
|
|
498
|
-
|
|
499
|
-
|
|
497
|
+
block_is_nilable = false
|
|
498
|
+
if block_type.is_a?(Type::Nilable)
|
|
499
|
+
block_is_nilable = true
|
|
500
|
+
block_type = block_type.type
|
|
500
501
|
end
|
|
501
502
|
|
|
502
|
-
|
|
503
|
+
type_string = parse_type(block_type).rbs_string.delete_prefix("^")
|
|
503
504
|
|
|
504
|
-
|
|
505
|
+
case block_type
|
|
506
|
+
when Type::Untyped
|
|
507
|
+
type_string = "(?) -> untyped"
|
|
508
|
+
block_is_nilable = true
|
|
509
|
+
when Type::Simple
|
|
510
|
+
return if block_type.name == "NilClass"
|
|
505
511
|
|
|
506
|
-
|
|
507
|
-
printl("(")
|
|
508
|
-
indent
|
|
509
|
-
params.each_with_index do |(sig_param, method_param), index|
|
|
510
|
-
printt
|
|
511
|
-
print_sig_param(
|
|
512
|
-
sig_param,
|
|
513
|
-
method_param, #: as !nil
|
|
514
|
-
)
|
|
515
|
-
print(",") if index < params.size - 1
|
|
516
|
-
printn
|
|
517
|
-
end
|
|
518
|
-
dedent
|
|
519
|
-
printt(") ")
|
|
512
|
+
type_string = "(?) -> untyped"
|
|
520
513
|
end
|
|
521
|
-
if (block_param = block_param&.first)
|
|
522
|
-
block_type = block_param.type
|
|
523
|
-
block_type = Type.parse_string(block_type) if block_type.is_a?(String)
|
|
524
|
-
|
|
525
|
-
block_is_nilable = false
|
|
526
|
-
if block_type.is_a?(Type::Nilable)
|
|
527
|
-
block_is_nilable = true
|
|
528
|
-
block_type = block_type.type
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
type_string = parse_type(block_type).rbs_string.delete_prefix("^")
|
|
532
514
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
block_is_nilable = true
|
|
538
|
-
when Type::Simple
|
|
539
|
-
type_string = "(?) -> untyped"
|
|
540
|
-
skip = true if block_type.name == "NilClass"
|
|
541
|
-
end
|
|
542
|
-
|
|
543
|
-
if skip
|
|
544
|
-
# no-op, we skip the block definition
|
|
545
|
-
elsif block_is_nilable
|
|
546
|
-
print("?{ #{type_string} } ")
|
|
547
|
-
else
|
|
548
|
-
print("{ #{type_string} } ")
|
|
549
|
-
end
|
|
515
|
+
if block_is_nilable
|
|
516
|
+
print("?{ #{type_string} } ")
|
|
517
|
+
else
|
|
518
|
+
print("{ #{type_string} } ")
|
|
550
519
|
end
|
|
551
|
-
|
|
552
|
-
type = parse_type(sig.return_type)
|
|
553
|
-
print("-> #{type.rbs_string}")
|
|
554
|
-
|
|
555
|
-
loc = sig.loc
|
|
556
|
-
print(" # #{loc}") if loc && print_locs
|
|
557
520
|
end
|
|
558
521
|
|
|
559
522
|
#: (Sig node) -> void
|
|
@@ -620,12 +583,24 @@ module RBI
|
|
|
620
583
|
print(" #{node.name}") unless node.anonymous?
|
|
621
584
|
end
|
|
622
585
|
|
|
586
|
+
# @override
|
|
587
|
+
#: (NoKwParam node) -> void
|
|
588
|
+
def visit_no_kw_param(node)
|
|
589
|
+
print("**nil")
|
|
590
|
+
end
|
|
591
|
+
|
|
623
592
|
# @override
|
|
624
593
|
#: (BlockParam node) -> void
|
|
625
594
|
def visit_block_param(node)
|
|
626
595
|
print("{ (*untyped) -> untyped } ")
|
|
627
596
|
end
|
|
628
597
|
|
|
598
|
+
# @override
|
|
599
|
+
#: (ForwardingParam node) -> void
|
|
600
|
+
def visit_forwarding_param(node)
|
|
601
|
+
print("...")
|
|
602
|
+
end
|
|
603
|
+
|
|
629
604
|
# @override
|
|
630
605
|
#: (Include node) -> void
|
|
631
606
|
def visit_include(node)
|
|
@@ -1116,9 +1091,12 @@ module RBI
|
|
|
1116
1091
|
@string << "singleton("
|
|
1117
1092
|
visit(type.type)
|
|
1118
1093
|
@string << ")"
|
|
1119
|
-
|
|
1094
|
+
unless type.type_parameters.empty?
|
|
1120
1095
|
@string << "["
|
|
1121
|
-
|
|
1096
|
+
type.type_parameters.each_with_index do |type_parameter, index|
|
|
1097
|
+
visit(type_parameter)
|
|
1098
|
+
@string << ", " if index < type.type_parameters.size - 1
|
|
1099
|
+
end
|
|
1122
1100
|
@string << "]"
|
|
1123
1101
|
end
|
|
1124
1102
|
end
|
|
@@ -44,13 +44,18 @@ module RBI
|
|
|
44
44
|
def add_method_sig(method)
|
|
45
45
|
return unless method.sigs.empty?
|
|
46
46
|
|
|
47
|
+
# Sorbet doesn't support signatures on methods using argument forwarding.
|
|
48
|
+
return if method.params.any?(RBI::ForwardingParam)
|
|
49
|
+
|
|
47
50
|
method.sigs << Sig.new(
|
|
48
|
-
params: method.params.
|
|
51
|
+
params: method.params.filter_map do |param|
|
|
49
52
|
case param
|
|
50
53
|
when RBI::RestParam
|
|
51
54
|
SigParam.new(param.name || "*", "::T.untyped")
|
|
52
55
|
when RBI::KwRestParam
|
|
53
56
|
SigParam.new(param.name || "**", "::T.untyped")
|
|
57
|
+
when RBI::NoKwParam
|
|
58
|
+
next
|
|
54
59
|
when RBI::BlockParam
|
|
55
60
|
SigParam.new(param.name || "&", "::T.untyped")
|
|
56
61
|
else
|