rbi 0.4.2 → 0.4.3
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/lib/rbi/model.rb +41 -1
- data/lib/rbi/parser.rb +37 -6
- data/lib/rbi/printer.rb +8 -1
- data/lib/rbi/rbs/method_type_translator.rb +1 -1
- data/lib/rbi/rbs/type_translator.rb +6 -3
- data/lib/rbi/rbs_printer.rb +72 -100
- data/lib/rbi/rewriters/add_sig_templates.rb +3 -1
- data/lib/rbi/rewriters/attr_to_methods.rb +1 -0
- 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 +5 -0
- data/rbi/rbi.rbi +65 -12
- 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: a187f51ebadb01bef099fcb043616e2006c6de1ca6c11ee1ad542c5289ae2a79
|
|
4
|
+
data.tar.gz: 50ab0f1cdee28c524c4519aee5d67dd67adac2cb6377137f2de84d114ebd4a3f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba665a75493caea2312e6dea8ae3267b2a20a693e51b026b71d5914858cfdc6ce2eb98f665eeb6e307ce51da9446fee82f269984e1872c615414179528c00745
|
|
7
|
+
data.tar.gz: a6da77cf6a8ec3a3bc1f9a89378b05d416213aef48bbcffaf699b5e6c43198d9f30a030cd590a0f9deb75dc058f7670743fabbd629e37ac012670ea2a1bd44b2
|
data/lib/rbi/model.rb
CHANGED
|
@@ -542,6 +542,11 @@ 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)
|
|
@@ -550,6 +555,7 @@ module RBI
|
|
|
550
555
|
#: (
|
|
551
556
|
#| ?params: Array[SigParam]?,
|
|
552
557
|
#| ?return_type: (String | Type),
|
|
558
|
+
#| ?bind_type: (String | Type)?,
|
|
553
559
|
#| ?is_abstract: bool,
|
|
554
560
|
#| ?is_override: bool,
|
|
555
561
|
#| ?is_overridable: bool,
|
|
@@ -559,6 +565,7 @@ module RBI
|
|
|
559
565
|
def add_sig(
|
|
560
566
|
params: [],
|
|
561
567
|
return_type: "void",
|
|
568
|
+
bind_type: nil,
|
|
562
569
|
is_abstract: false,
|
|
563
570
|
is_override: false,
|
|
564
571
|
is_overridable: false,
|
|
@@ -570,6 +577,7 @@ module RBI
|
|
|
570
577
|
sig = Sig.new(
|
|
571
578
|
params: params,
|
|
572
579
|
return_type: return_type,
|
|
580
|
+
bind_type: bind_type,
|
|
573
581
|
is_abstract: is_abstract,
|
|
574
582
|
is_override: is_override,
|
|
575
583
|
is_overridable: is_overridable,
|
|
@@ -807,6 +815,31 @@ module RBI
|
|
|
807
815
|
end
|
|
808
816
|
end
|
|
809
817
|
|
|
818
|
+
class NoKwParam < Param
|
|
819
|
+
#: (?loc: Loc?, ?comments: Array[Comment]?) ?{ (NoKwParam node) -> void } -> void
|
|
820
|
+
def initialize(loc: nil, comments: nil, &block)
|
|
821
|
+
super(loc: loc, comments: comments)
|
|
822
|
+
block&.call(self)
|
|
823
|
+
end
|
|
824
|
+
|
|
825
|
+
# @override
|
|
826
|
+
#: -> String
|
|
827
|
+
def to_s
|
|
828
|
+
"**nil"
|
|
829
|
+
end
|
|
830
|
+
|
|
831
|
+
# @override
|
|
832
|
+
#: -> bool
|
|
833
|
+
def anonymous?
|
|
834
|
+
false
|
|
835
|
+
end
|
|
836
|
+
|
|
837
|
+
#: (Object? other) -> bool
|
|
838
|
+
def ==(other)
|
|
839
|
+
NoKwParam === other
|
|
840
|
+
end
|
|
841
|
+
end
|
|
842
|
+
|
|
810
843
|
class BlockParam < Param
|
|
811
844
|
# @override
|
|
812
845
|
#: String?
|
|
@@ -1028,6 +1061,9 @@ module RBI
|
|
|
1028
1061
|
#: (Type | String)
|
|
1029
1062
|
attr_accessor :return_type
|
|
1030
1063
|
|
|
1064
|
+
#: (Type | String)?
|
|
1065
|
+
attr_accessor :bind_type
|
|
1066
|
+
|
|
1031
1067
|
#: bool
|
|
1032
1068
|
attr_accessor :is_abstract
|
|
1033
1069
|
|
|
@@ -1065,6 +1101,7 @@ module RBI
|
|
|
1065
1101
|
#: (
|
|
1066
1102
|
#| ?params: Array[SigParam]?,
|
|
1067
1103
|
#| ?return_type: (Type | String),
|
|
1104
|
+
#| ?bind_type: (Type | String)?,
|
|
1068
1105
|
#| ?is_abstract: bool,
|
|
1069
1106
|
#| ?is_override: bool,
|
|
1070
1107
|
#| ?is_overridable: bool,
|
|
@@ -1080,6 +1117,7 @@ module RBI
|
|
|
1080
1117
|
def initialize(
|
|
1081
1118
|
params: nil,
|
|
1082
1119
|
return_type: "void",
|
|
1120
|
+
bind_type: nil,
|
|
1083
1121
|
is_abstract: false,
|
|
1084
1122
|
is_override: false,
|
|
1085
1123
|
is_overridable: false,
|
|
@@ -1096,6 +1134,7 @@ module RBI
|
|
|
1096
1134
|
super(loc: loc, comments: comments)
|
|
1097
1135
|
@params = params #: Array[SigParam]?
|
|
1098
1136
|
@return_type = return_type
|
|
1137
|
+
@bind_type = bind_type
|
|
1099
1138
|
@is_abstract = is_abstract
|
|
1100
1139
|
@is_override = is_override
|
|
1101
1140
|
@is_overridable = is_overridable
|
|
@@ -1122,7 +1161,8 @@ module RBI
|
|
|
1122
1161
|
def ==(other)
|
|
1123
1162
|
return false unless other.is_a?(Sig)
|
|
1124
1163
|
|
|
1125
|
-
params == other.params && return_type.to_s == other.return_type.to_s &&
|
|
1164
|
+
params == other.params && return_type.to_s == other.return_type.to_s &&
|
|
1165
|
+
bind_type&.to_s == other.bind_type&.to_s && is_abstract == other.is_abstract &&
|
|
1126
1166
|
is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
|
|
1127
1167
|
without_runtime == other.without_runtime && type_params == other.type_params && checked == other.checked
|
|
1128
1168
|
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(
|
|
@@ -743,6 +758,11 @@ module RBI
|
|
|
743
758
|
loc: node_loc(param),
|
|
744
759
|
comments: node_comments(param),
|
|
745
760
|
)
|
|
761
|
+
when Prism::NoKeywordsParameterNode
|
|
762
|
+
NoKwParam.new(
|
|
763
|
+
loc: node_loc(param),
|
|
764
|
+
comments: node_comments(param),
|
|
765
|
+
)
|
|
746
766
|
when Prism::KeywordRestParameterNode
|
|
747
767
|
KwRestParam.new(
|
|
748
768
|
param.name&.to_s,
|
|
@@ -828,7 +848,7 @@ module RBI
|
|
|
828
848
|
return unless type_arg
|
|
829
849
|
|
|
830
850
|
name = node_string!(name_arg).delete_prefix(":")
|
|
831
|
-
type =
|
|
851
|
+
type = type_string(type_arg)
|
|
832
852
|
loc = node_loc(send)
|
|
833
853
|
comments = node_comments(send)
|
|
834
854
|
default_value = nil #: String?
|
|
@@ -936,6 +956,9 @@ module RBI
|
|
|
936
956
|
@current.is_final = node_string(arg) == ":final"
|
|
937
957
|
end
|
|
938
958
|
end
|
|
959
|
+
when "bind"
|
|
960
|
+
bind_type = sig_type_argument(node)
|
|
961
|
+
@current.bind_type = bind_type if bind_type
|
|
939
962
|
when "abstract"
|
|
940
963
|
@current.is_abstract = true
|
|
941
964
|
when "checked"
|
|
@@ -953,11 +976,8 @@ module RBI
|
|
|
953
976
|
when "params"
|
|
954
977
|
visit(node.arguments)
|
|
955
978
|
when "returns"
|
|
956
|
-
|
|
957
|
-
if
|
|
958
|
-
first = args.arguments.first
|
|
959
|
-
@current.return_type = node_string!(first) if first
|
|
960
|
-
end
|
|
979
|
+
return_type = sig_type_argument(node)
|
|
980
|
+
@current.return_type = return_type if return_type
|
|
961
981
|
when "type_parameters"
|
|
962
982
|
args = node.arguments
|
|
963
983
|
if args.is_a?(Prism::ArgumentsNode)
|
|
@@ -982,6 +1002,17 @@ module RBI
|
|
|
982
1002
|
)
|
|
983
1003
|
end
|
|
984
1004
|
|
|
1005
|
+
#: (Prism::CallNode node) -> String?
|
|
1006
|
+
def sig_type_argument(node)
|
|
1007
|
+
args = node.arguments
|
|
1008
|
+
return unless args.is_a?(Prism::ArgumentsNode)
|
|
1009
|
+
|
|
1010
|
+
type_node = args.arguments.first
|
|
1011
|
+
return unless type_node
|
|
1012
|
+
|
|
1013
|
+
type_string(type_node)
|
|
1014
|
+
end
|
|
1015
|
+
|
|
985
1016
|
#: (Prism::Node node) -> String
|
|
986
1017
|
def sig_param_name(node)
|
|
987
1018
|
case node
|
data/lib/rbi/printer.rb
CHANGED
|
@@ -396,6 +396,12 @@ 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)
|
|
@@ -829,7 +835,7 @@ module RBI
|
|
|
829
835
|
|
|
830
836
|
#: (Sig node) -> Array[String]
|
|
831
837
|
def sig_modifiers(node)
|
|
832
|
-
return EMPTY_MODIFIERS unless node.is_abstract || node.is_override || node.is_overridable ||
|
|
838
|
+
return EMPTY_MODIFIERS unless node.is_abstract || node.is_override || node.is_overridable || node.bind_type ||
|
|
833
839
|
node.type_params? || node.checked
|
|
834
840
|
|
|
835
841
|
modifiers = [] #: Array[String]
|
|
@@ -846,6 +852,7 @@ module RBI
|
|
|
846
852
|
end
|
|
847
853
|
|
|
848
854
|
modifiers << "overridable" if node.is_overridable
|
|
855
|
+
modifiers << "bind(#{node.bind_type})" if node.bind_type
|
|
849
856
|
if node.type_params?
|
|
850
857
|
modifiers << "type_parameters(#{node.type_params.map { |type| ":#{type}" }.join(", ")})"
|
|
851
858
|
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
|
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,6 +583,12 @@ 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)
|
|
@@ -1116,9 +1085,12 @@ module RBI
|
|
|
1116
1085
|
@string << "singleton("
|
|
1117
1086
|
visit(type.type)
|
|
1118
1087
|
@string << ")"
|
|
1119
|
-
|
|
1088
|
+
unless type.type_parameters.empty?
|
|
1120
1089
|
@string << "["
|
|
1121
|
-
|
|
1090
|
+
type.type_parameters.each_with_index do |type_parameter, index|
|
|
1091
|
+
visit(type_parameter)
|
|
1092
|
+
@string << ", " if index < type.type_parameters.size - 1
|
|
1093
|
+
end
|
|
1122
1094
|
@string << "]"
|
|
1123
1095
|
end
|
|
1124
1096
|
end
|
|
@@ -45,12 +45,14 @@ module RBI
|
|
|
45
45
|
return unless method.sigs.empty?
|
|
46
46
|
|
|
47
47
|
method.sigs << Sig.new(
|
|
48
|
-
params: method.params.
|
|
48
|
+
params: method.params.filter_map do |param|
|
|
49
49
|
case param
|
|
50
50
|
when RBI::RestParam
|
|
51
51
|
SigParam.new(param.name || "*", "::T.untyped")
|
|
52
52
|
when RBI::KwRestParam
|
|
53
53
|
SigParam.new(param.name || "**", "::T.untyped")
|
|
54
|
+
when RBI::NoKwParam
|
|
55
|
+
next
|
|
54
56
|
when RBI::BlockParam
|
|
55
57
|
SigParam.new(param.name || "&", "::T.untyped")
|
|
56
58
|
else
|
data/lib/rbi/type.rb
CHANGED
|
@@ -315,29 +315,29 @@ module RBI
|
|
|
315
315
|
#: Simple
|
|
316
316
|
attr_reader :type
|
|
317
317
|
|
|
318
|
-
#: Type
|
|
319
|
-
attr_reader :
|
|
318
|
+
#: Array[Type]
|
|
319
|
+
attr_reader :type_parameters
|
|
320
320
|
|
|
321
|
-
#: (Simple type,
|
|
322
|
-
def initialize(type,
|
|
321
|
+
#: (Simple type, *Type type_parameters) -> void
|
|
322
|
+
def initialize(type, *type_parameters)
|
|
323
323
|
super()
|
|
324
324
|
@type = type
|
|
325
|
-
@
|
|
325
|
+
@type_parameters = type_parameters #: Array[Type]
|
|
326
326
|
end
|
|
327
327
|
|
|
328
328
|
# @override
|
|
329
329
|
#: (BasicObject other) -> bool
|
|
330
330
|
def ==(other)
|
|
331
|
-
ClassOf === other && @type == other.type && @
|
|
331
|
+
ClassOf === other && @type == other.type && @type_parameters == other.type_parameters
|
|
332
332
|
end
|
|
333
333
|
|
|
334
334
|
# @override
|
|
335
335
|
#: -> String
|
|
336
336
|
def to_rbi
|
|
337
|
-
if @
|
|
338
|
-
"::T.class_of(#{@type.to_rbi})[#{@type_parameter.to_rbi}]"
|
|
339
|
-
else
|
|
337
|
+
if @type_parameters.empty?
|
|
340
338
|
"::T.class_of(#{@type.to_rbi})"
|
|
339
|
+
else
|
|
340
|
+
"::T.class_of(#{@type.to_rbi})[#{@type_parameters.map(&:to_rbi).join(", ")}]"
|
|
341
341
|
end
|
|
342
342
|
end
|
|
343
343
|
|
|
@@ -913,9 +913,9 @@ module RBI
|
|
|
913
913
|
end
|
|
914
914
|
|
|
915
915
|
# Builds a type that represents the singleton class of another type like `T.class_of(Foo)`.
|
|
916
|
-
#: (Simple type,
|
|
917
|
-
def class_of(type,
|
|
918
|
-
ClassOf.new(type,
|
|
916
|
+
#: (Simple type, *(Type | Array[Type]) type_parameters) -> ClassOf
|
|
917
|
+
def class_of(type, *type_parameters)
|
|
918
|
+
ClassOf.new(type, *type_parameters.flatten)
|
|
919
919
|
end
|
|
920
920
|
|
|
921
921
|
# Builds a type that represents a nilable of another type like `T.nilable(String)`.
|
data/lib/rbi/type_parser.rb
CHANGED
|
@@ -130,7 +130,7 @@ module RBI
|
|
|
130
130
|
return Type::Generic.new(recv.slice, *args.map { |arg| parse_node(arg) })
|
|
131
131
|
end
|
|
132
132
|
when Prism::CallNode
|
|
133
|
-
# `T.class_of(Foo)[Bar]`
|
|
133
|
+
# `T.class_of(Foo)[Foo]` or `T.class_of(Foo)[Foo, Bar]`
|
|
134
134
|
if t_class_of?(recv)
|
|
135
135
|
type_args = check_arguments_exactly!(recv, 1)
|
|
136
136
|
type = parse_node(
|
|
@@ -138,11 +138,9 @@ module RBI
|
|
|
138
138
|
)
|
|
139
139
|
raise Error, "Expected a simple type, got `#{type}`" unless type.is_a?(Type::Simple)
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
return Type::ClassOf.new(type, type_param)
|
|
141
|
+
type_parameter_args = check_arguments_at_least!(node, 1)
|
|
142
|
+
type_parameters = type_parameter_args.map { |arg| parse_node(arg) }
|
|
143
|
+
return Type::ClassOf.new(type, *type_parameters)
|
|
146
144
|
end
|
|
147
145
|
end
|
|
148
146
|
|
data/lib/rbi/version.rb
CHANGED
data/lib/rbi/visitor.rb
CHANGED
|
@@ -63,6 +63,8 @@ module RBI
|
|
|
63
63
|
visit_kw_opt_param(node)
|
|
64
64
|
when KwRestParam
|
|
65
65
|
visit_kw_rest_param(node)
|
|
66
|
+
when NoKwParam
|
|
67
|
+
visit_no_kw_param(node)
|
|
66
68
|
when BlockParam
|
|
67
69
|
visit_block_param(node)
|
|
68
70
|
when Include
|
|
@@ -173,6 +175,9 @@ module RBI
|
|
|
173
175
|
#: (KwRestParam node) -> void
|
|
174
176
|
def visit_kw_rest_param(node); end
|
|
175
177
|
|
|
178
|
+
#: (NoKwParam node) -> void
|
|
179
|
+
def visit_no_kw_param(node); end
|
|
180
|
+
|
|
176
181
|
#: (BlockParam node) -> void
|
|
177
182
|
def visit_block_param(node); end
|
|
178
183
|
|
data/rbi/rbi.rbi
CHANGED
|
@@ -698,6 +698,9 @@ class RBI::Method < ::RBI::NodeWithComments
|
|
|
698
698
|
sig { params(name: ::String).void }
|
|
699
699
|
def add_kw_rest_param(name); end
|
|
700
700
|
|
|
701
|
+
sig { void }
|
|
702
|
+
def add_no_kw_param; end
|
|
703
|
+
|
|
701
704
|
sig { params(name: ::String, default_value: ::String).void }
|
|
702
705
|
def add_opt_param(name, default_value); end
|
|
703
706
|
|
|
@@ -711,6 +714,7 @@ class RBI::Method < ::RBI::NodeWithComments
|
|
|
711
714
|
params(
|
|
712
715
|
params: T.nilable(T::Array[::RBI::SigParam]),
|
|
713
716
|
return_type: T.any(::RBI::Type, ::String),
|
|
717
|
+
bind_type: T.nilable(T.any(::RBI::Type, ::String)),
|
|
714
718
|
is_abstract: T::Boolean,
|
|
715
719
|
is_override: T::Boolean,
|
|
716
720
|
is_overridable: T::Boolean,
|
|
@@ -720,7 +724,7 @@ class RBI::Method < ::RBI::NodeWithComments
|
|
|
720
724
|
block: T.nilable(T.proc.params(node: ::RBI::Sig).void)
|
|
721
725
|
).void
|
|
722
726
|
end
|
|
723
|
-
def add_sig(params: T.unsafe(nil), return_type: T.unsafe(nil), is_abstract: T.unsafe(nil), is_override: T.unsafe(nil), is_overridable: T.unsafe(nil), is_final: T.unsafe(nil), type_params: T.unsafe(nil), checked: T.unsafe(nil), &block); end
|
|
727
|
+
def add_sig(params: T.unsafe(nil), return_type: T.unsafe(nil), bind_type: T.unsafe(nil), is_abstract: T.unsafe(nil), is_override: T.unsafe(nil), is_overridable: T.unsafe(nil), is_final: T.unsafe(nil), type_params: T.unsafe(nil), checked: T.unsafe(nil), &block); end
|
|
724
728
|
|
|
725
729
|
sig { override.params(other: ::RBI::Node).returns(T::Boolean) }
|
|
726
730
|
def compatible_with?(other); end
|
|
@@ -839,6 +843,26 @@ class RBI::Module < ::RBI::Scope
|
|
|
839
843
|
def name; end
|
|
840
844
|
end
|
|
841
845
|
|
|
846
|
+
class RBI::NoKwParam < ::RBI::Param
|
|
847
|
+
sig do
|
|
848
|
+
params(
|
|
849
|
+
loc: T.nilable(::RBI::Loc),
|
|
850
|
+
comments: T.nilable(T::Array[::RBI::Comment]),
|
|
851
|
+
block: T.nilable(T.proc.params(node: ::RBI::NoKwParam).void)
|
|
852
|
+
).void
|
|
853
|
+
end
|
|
854
|
+
def initialize(loc: T.unsafe(nil), comments: T.unsafe(nil), &block); end
|
|
855
|
+
|
|
856
|
+
sig { params(other: T.nilable(::Object)).returns(T::Boolean) }
|
|
857
|
+
def ==(other); end
|
|
858
|
+
|
|
859
|
+
sig { override.returns(T::Boolean) }
|
|
860
|
+
def anonymous?; end
|
|
861
|
+
|
|
862
|
+
sig { override.returns(::String) }
|
|
863
|
+
def to_s; end
|
|
864
|
+
end
|
|
865
|
+
|
|
842
866
|
class RBI::Node
|
|
843
867
|
abstract!
|
|
844
868
|
|
|
@@ -1039,6 +1063,9 @@ class RBI::Parser::SigBuilder < ::RBI::Parser::Visitor
|
|
|
1039
1063
|
sig { params(node: ::Prism::Node).returns(::String) }
|
|
1040
1064
|
def sig_param_name(node); end
|
|
1041
1065
|
|
|
1066
|
+
sig { params(node: ::Prism::CallNode).returns(T.nilable(::String)) }
|
|
1067
|
+
def sig_type_argument(node); end
|
|
1068
|
+
|
|
1042
1069
|
sig { override.params(node: ::Prism::AssocNode).void }
|
|
1043
1070
|
def visit_assoc_node(node); end
|
|
1044
1071
|
|
|
@@ -1150,6 +1177,9 @@ class RBI::Parser::Visitor < ::Prism::Visitor
|
|
|
1150
1177
|
sig { params(node: ::Prism::Node).returns(::Prism::Location) }
|
|
1151
1178
|
def adjust_prism_location_for_heredoc(node); end
|
|
1152
1179
|
|
|
1180
|
+
sig { params(node: ::Prism::Node).returns(T::Boolean) }
|
|
1181
|
+
def braceless_shape?(node); end
|
|
1182
|
+
|
|
1153
1183
|
sig { params(node: ::Prism::Node).returns(::RBI::Loc) }
|
|
1154
1184
|
def node_loc(node); end
|
|
1155
1185
|
|
|
@@ -1164,6 +1194,9 @@ class RBI::Parser::Visitor < ::Prism::Visitor
|
|
|
1164
1194
|
|
|
1165
1195
|
sig { params(node: T.nilable(::Prism::Node)).returns(T::Boolean) }
|
|
1166
1196
|
def t_sig_without_runtime?(node); end
|
|
1197
|
+
|
|
1198
|
+
sig { params(node: ::Prism::Node).returns(::String) }
|
|
1199
|
+
def type_string(node); end
|
|
1167
1200
|
end
|
|
1168
1201
|
|
|
1169
1202
|
class RBI::Printer < ::RBI::Visitor
|
|
@@ -1316,6 +1349,9 @@ class RBI::Printer < ::RBI::Visitor
|
|
|
1316
1349
|
sig { override.params(node: ::RBI::Module).void }
|
|
1317
1350
|
def visit_module(node); end
|
|
1318
1351
|
|
|
1352
|
+
sig { override.params(node: ::RBI::NoKwParam).void }
|
|
1353
|
+
def visit_no_kw_param(node); end
|
|
1354
|
+
|
|
1319
1355
|
sig { override.params(node: ::RBI::OptParam).void }
|
|
1320
1356
|
def visit_opt_param(node); end
|
|
1321
1357
|
|
|
@@ -1589,11 +1625,11 @@ class RBI::RBSPrinter < ::RBI::Visitor
|
|
|
1589
1625
|
sig { params(node: ::RBI::Method, sig: ::RBI::Sig).void }
|
|
1590
1626
|
def print_method_sig(node, sig); end
|
|
1591
1627
|
|
|
1592
|
-
sig { params(
|
|
1593
|
-
def
|
|
1628
|
+
sig { params(sig_param: T.nilable(::RBI::SigParam)).void }
|
|
1629
|
+
def print_method_sig_block(sig_param); end
|
|
1594
1630
|
|
|
1595
|
-
sig { params(node: ::RBI::Method, sig: ::RBI::Sig).void }
|
|
1596
|
-
def
|
|
1631
|
+
sig { params(node: ::RBI::Method, sig: ::RBI::Sig, multiline: T::Boolean).void }
|
|
1632
|
+
def print_method_sig_content(node, sig, multiline:); end
|
|
1597
1633
|
|
|
1598
1634
|
sig { params(string: ::String).void }
|
|
1599
1635
|
def printl(string); end
|
|
@@ -1679,6 +1715,9 @@ class RBI::RBSPrinter < ::RBI::Visitor
|
|
|
1679
1715
|
sig { override.params(node: ::RBI::Module).void }
|
|
1680
1716
|
def visit_module(node); end
|
|
1681
1717
|
|
|
1718
|
+
sig { override.params(node: ::RBI::NoKwParam).void }
|
|
1719
|
+
def visit_no_kw_param(node); end
|
|
1720
|
+
|
|
1682
1721
|
sig { override.params(node: ::RBI::OptParam).void }
|
|
1683
1722
|
def visit_opt_param(node); end
|
|
1684
1723
|
|
|
@@ -2229,6 +2268,7 @@ class RBI::Sig < ::RBI::NodeWithComments
|
|
|
2229
2268
|
params(
|
|
2230
2269
|
params: T.nilable(T::Array[::RBI::SigParam]),
|
|
2231
2270
|
return_type: T.any(::RBI::Type, ::String),
|
|
2271
|
+
bind_type: T.nilable(T.any(::RBI::Type, ::String)),
|
|
2232
2272
|
is_abstract: T::Boolean,
|
|
2233
2273
|
is_override: T::Boolean,
|
|
2234
2274
|
is_overridable: T::Boolean,
|
|
@@ -2243,7 +2283,7 @@ class RBI::Sig < ::RBI::NodeWithComments
|
|
|
2243
2283
|
block: T.nilable(T.proc.params(node: ::RBI::Sig).void)
|
|
2244
2284
|
).void
|
|
2245
2285
|
end
|
|
2246
|
-
def initialize(params: T.unsafe(nil), return_type: T.unsafe(nil), is_abstract: T.unsafe(nil), is_override: T.unsafe(nil), is_overridable: T.unsafe(nil), is_final: T.unsafe(nil), allow_incompatible_override: T.unsafe(nil), allow_incompatible_override_visibility: T.unsafe(nil), without_runtime: T.unsafe(nil), type_params: T.unsafe(nil), checked: T.unsafe(nil), loc: T.unsafe(nil), comments: T.unsafe(nil), &block); end
|
|
2286
|
+
def initialize(params: T.unsafe(nil), return_type: T.unsafe(nil), bind_type: T.unsafe(nil), is_abstract: T.unsafe(nil), is_override: T.unsafe(nil), is_overridable: T.unsafe(nil), is_final: T.unsafe(nil), allow_incompatible_override: T.unsafe(nil), allow_incompatible_override_visibility: T.unsafe(nil), without_runtime: T.unsafe(nil), type_params: T.unsafe(nil), checked: T.unsafe(nil), loc: T.unsafe(nil), comments: T.unsafe(nil), &block); end
|
|
2247
2287
|
|
|
2248
2288
|
sig { params(param: ::RBI::SigParam).void }
|
|
2249
2289
|
def <<(param); end
|
|
@@ -2264,6 +2304,11 @@ class RBI::Sig < ::RBI::NodeWithComments
|
|
|
2264
2304
|
|
|
2265
2305
|
def allow_incompatible_override_visibility=(_arg0); end
|
|
2266
2306
|
|
|
2307
|
+
sig { returns(T.nilable(T.any(::RBI::Type, ::String))) }
|
|
2308
|
+
def bind_type; end
|
|
2309
|
+
|
|
2310
|
+
def bind_type=(_arg0); end
|
|
2311
|
+
|
|
2267
2312
|
sig { returns(T.nilable(::Symbol)) }
|
|
2268
2313
|
def checked; end
|
|
2269
2314
|
|
|
@@ -2671,8 +2716,13 @@ class RBI::Type
|
|
|
2671
2716
|
sig { returns(::RBI::Type::Boolean) }
|
|
2672
2717
|
def boolean; end
|
|
2673
2718
|
|
|
2674
|
-
sig
|
|
2675
|
-
|
|
2719
|
+
sig do
|
|
2720
|
+
params(
|
|
2721
|
+
type: ::RBI::Type::Simple,
|
|
2722
|
+
type_parameters: T.any(::RBI::Type, T::Array[::RBI::Type])
|
|
2723
|
+
).returns(::RBI::Type::ClassOf)
|
|
2724
|
+
end
|
|
2725
|
+
def class_of(type, *type_parameters); end
|
|
2676
2726
|
|
|
2677
2727
|
sig { params(name: ::String, params: T.any(::RBI::Type, T::Array[::RBI::Type])).returns(::RBI::Type::Generic) }
|
|
2678
2728
|
def generic(name, *params); end
|
|
@@ -2865,8 +2915,8 @@ class RBI::Type::Class < ::RBI::Type
|
|
|
2865
2915
|
end
|
|
2866
2916
|
|
|
2867
2917
|
class RBI::Type::ClassOf < ::RBI::Type
|
|
2868
|
-
sig { params(type: ::RBI::Type::Simple,
|
|
2869
|
-
def initialize(type,
|
|
2918
|
+
sig { params(type: ::RBI::Type::Simple, type_parameters: ::RBI::Type).void }
|
|
2919
|
+
def initialize(type, *type_parameters); end
|
|
2870
2920
|
|
|
2871
2921
|
sig { override.params(other: ::BasicObject).returns(T::Boolean) }
|
|
2872
2922
|
def ==(other); end
|
|
@@ -2883,8 +2933,8 @@ class RBI::Type::ClassOf < ::RBI::Type
|
|
|
2883
2933
|
sig { returns(::RBI::Type::Simple) }
|
|
2884
2934
|
def type; end
|
|
2885
2935
|
|
|
2886
|
-
sig { returns(T
|
|
2887
|
-
def
|
|
2936
|
+
sig { returns(T::Array[::RBI::Type]) }
|
|
2937
|
+
def type_parameters; end
|
|
2888
2938
|
end
|
|
2889
2939
|
|
|
2890
2940
|
class RBI::Type::Composite < ::RBI::Type
|
|
@@ -3458,6 +3508,9 @@ class RBI::Visitor
|
|
|
3458
3508
|
sig { params(node: ::RBI::Module).void }
|
|
3459
3509
|
def visit_module(node); end
|
|
3460
3510
|
|
|
3511
|
+
sig { params(node: ::RBI::NoKwParam).void }
|
|
3512
|
+
def visit_no_kw_param(node); end
|
|
3513
|
+
|
|
3461
3514
|
sig { params(node: ::RBI::OptParam).void }
|
|
3462
3515
|
def visit_opt_param(node); end
|
|
3463
3516
|
|