rbi 0.3.2 → 0.3.5
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 +2 -2
- data/lib/rbi/index.rb +3 -8
- data/lib/rbi/loc.rb +11 -0
- data/lib/rbi/model.rb +19 -41
- data/lib/rbi/parser.rb +119 -71
- data/lib/rbi/printer.rb +6 -2
- data/lib/rbi/rbs/type_translator.rb +26 -30
- data/lib/rbi/rbs_printer.rb +103 -5
- data/lib/rbi/rewriters/attr_to_methods.rb +2 -1
- data/lib/rbi/rewriters/group_nodes.rb +16 -16
- data/lib/rbi/rewriters/merge_trees.rb +20 -11
- data/lib/rbi/rewriters/remove_known_definitions.rb +9 -3
- data/lib/rbi/rewriters/sort_nodes.rb +1 -1
- data/lib/rbi/type.rb +336 -100
- data/lib/rbi/type_parser.rb +7 -5
- data/lib/rbi/version.rb +1 -1
- data/lib/rbi/visitor.rb +1 -4
- data/lib/rbi.rb +0 -1
- data/rbi/rbi.rbi +258 -88
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8a42ab1d61b3ca13faf2257a62127bb43088d92aec433711820f68333c1a550
|
4
|
+
data.tar.gz: 86fc4e3e2ad745b719272569426d667195a241ecbfd3aa42703e29819bd23d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c668f46c96e059154b09afe9e1e33efc8135d5bf8a92debb63a1378a6362004b86fa29df097a1e64fd1db60d7ee243f4560a3ee878f4c40d7aceccfc55755a1
|
7
|
+
data.tar.gz: 1d7248cfa39b703ecd02c444013148b2208dcc560d49f470024a6f718687e4ec7ef336c1cd1fd6161d8e54fc80d1d39484af39076dac82dacb6577eccb9b7965
|
data/Gemfile
CHANGED
@@ -9,8 +9,8 @@ group(:development, :test) do
|
|
9
9
|
gem("byebug")
|
10
10
|
gem("minitest")
|
11
11
|
gem("minitest-reporters")
|
12
|
-
gem("rake", "~> 13.
|
13
|
-
gem("rubocop", "~> 1.
|
12
|
+
gem("rake", "~> 13.3")
|
13
|
+
gem("rubocop", "~> 1.76", 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/index.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
module RBI
|
5
5
|
class Index < Visitor
|
6
|
-
include T::Enumerable
|
7
|
-
|
8
6
|
class << self
|
9
7
|
#: (*Node node) -> Index
|
10
8
|
def index(*node)
|
@@ -67,17 +65,14 @@ module RBI
|
|
67
65
|
end
|
68
66
|
|
69
67
|
# A Node that can be referred to by a unique ID inside an index
|
68
|
+
# @interface
|
70
69
|
module Indexable
|
71
|
-
extend T::Sig
|
72
|
-
extend T::Helpers
|
73
|
-
|
74
|
-
interface!
|
75
|
-
|
76
70
|
# Unique IDs that refer to this node.
|
77
71
|
#
|
78
72
|
# Some nodes can have multiple ids, for example an attribute accessor matches the ID of the
|
79
73
|
# getter and the setter.
|
80
|
-
|
74
|
+
# @abstract
|
75
|
+
#: -> Array[String]
|
81
76
|
def index_ids; end
|
82
77
|
end
|
83
78
|
|
data/lib/rbi/loc.rb
CHANGED
@@ -31,6 +31,17 @@ module RBI
|
|
31
31
|
@end_column = end_column
|
32
32
|
end
|
33
33
|
|
34
|
+
#: (Loc) -> Loc
|
35
|
+
def join(other)
|
36
|
+
Loc.new(
|
37
|
+
file: file,
|
38
|
+
begin_line: begin_line,
|
39
|
+
begin_column: begin_column,
|
40
|
+
end_line: other.end_line,
|
41
|
+
end_column: other.end_column,
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
34
45
|
#: -> String
|
35
46
|
def to_s
|
36
47
|
if end_line && end_column
|
data/lib/rbi/model.rb
CHANGED
@@ -4,11 +4,8 @@
|
|
4
4
|
module RBI
|
5
5
|
class ReplaceNodeError < Error; end
|
6
6
|
|
7
|
+
# @abstract
|
7
8
|
class Node
|
8
|
-
extend T::Helpers
|
9
|
-
|
10
|
-
abstract!
|
11
|
-
|
12
9
|
#: Tree?
|
13
10
|
attr_accessor :parent_tree
|
14
11
|
|
@@ -87,11 +84,8 @@ module RBI
|
|
87
84
|
end
|
88
85
|
end
|
89
86
|
|
87
|
+
# @abstract
|
90
88
|
class NodeWithComments < Node
|
91
|
-
extend T::Helpers
|
92
|
-
|
93
|
-
abstract!
|
94
|
-
|
95
89
|
#: Array[Comment]
|
96
90
|
attr_accessor :comments
|
97
91
|
|
@@ -165,13 +159,10 @@ module RBI
|
|
165
159
|
|
166
160
|
# Scopes
|
167
161
|
|
162
|
+
# @abstract
|
168
163
|
class Scope < Tree
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
abstract!
|
173
|
-
|
174
|
-
sig { abstract.returns(String) }
|
164
|
+
# @abstract
|
165
|
+
#: -> String
|
175
166
|
def fully_qualified_name; end
|
176
167
|
|
177
168
|
# @override
|
@@ -297,12 +288,8 @@ module RBI
|
|
297
288
|
|
298
289
|
# Attributes
|
299
290
|
|
291
|
+
# @abstract
|
300
292
|
class Attr < NodeWithComments
|
301
|
-
extend T::Sig
|
302
|
-
extend T::Helpers
|
303
|
-
|
304
|
-
abstract!
|
305
|
-
|
306
293
|
#: Array[Symbol]
|
307
294
|
attr_reader :names
|
308
295
|
|
@@ -320,7 +307,8 @@ module RBI
|
|
320
307
|
@sigs = sigs
|
321
308
|
end
|
322
309
|
|
323
|
-
|
310
|
+
# @abstract
|
311
|
+
#: -> Array[String]
|
324
312
|
def fully_qualified_names; end
|
325
313
|
end
|
326
314
|
|
@@ -510,11 +498,8 @@ module RBI
|
|
510
498
|
end
|
511
499
|
end
|
512
500
|
|
501
|
+
# @abstract
|
513
502
|
class Param < NodeWithComments
|
514
|
-
extend T::Helpers
|
515
|
-
|
516
|
-
abstract!
|
517
|
-
|
518
503
|
#: String
|
519
504
|
attr_reader :name
|
520
505
|
|
@@ -662,11 +647,8 @@ module RBI
|
|
662
647
|
|
663
648
|
# Mixins
|
664
649
|
|
650
|
+
# @abstract
|
665
651
|
class Mixin < NodeWithComments
|
666
|
-
extend T::Helpers
|
667
|
-
|
668
|
-
abstract!
|
669
|
-
|
670
652
|
#: Array[String]
|
671
653
|
attr_reader :names
|
672
654
|
|
@@ -707,11 +689,8 @@ module RBI
|
|
707
689
|
|
708
690
|
# Visibility
|
709
691
|
|
692
|
+
# @abstract
|
710
693
|
class Visibility < NodeWithComments
|
711
|
-
extend T::Helpers
|
712
|
-
|
713
|
-
abstract!
|
714
|
-
|
715
694
|
#: Symbol
|
716
695
|
attr_reader :visibility
|
717
696
|
|
@@ -853,7 +832,7 @@ module RBI
|
|
853
832
|
attr_accessor :return_type
|
854
833
|
|
855
834
|
#: bool
|
856
|
-
attr_accessor :is_abstract, :is_override, :is_overridable, :is_final, :allow_incompatible_override
|
835
|
+
attr_accessor :is_abstract, :is_override, :is_overridable, :is_final, :allow_incompatible_override, :without_runtime
|
857
836
|
|
858
837
|
#: Array[String]
|
859
838
|
attr_reader :type_params
|
@@ -861,7 +840,7 @@ module RBI
|
|
861
840
|
#: Symbol?
|
862
841
|
attr_accessor :checked
|
863
842
|
|
864
|
-
#: (?params: Array[SigParam], ?return_type: (Type | String), ?is_abstract: bool, ?is_override: bool, ?is_overridable: bool, ?is_final: bool, ?allow_incompatible_override: bool, ?type_params: Array[String], ?checked: Symbol?, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Sig node) -> void } -> void
|
843
|
+
#: (?params: Array[SigParam], ?return_type: (Type | String), ?is_abstract: bool, ?is_override: bool, ?is_overridable: bool, ?is_final: bool, ?allow_incompatible_override: bool, ?without_runtime: bool, ?type_params: Array[String], ?checked: Symbol?, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Sig node) -> void } -> void
|
865
844
|
def initialize(
|
866
845
|
params: [],
|
867
846
|
return_type: "void",
|
@@ -870,6 +849,7 @@ module RBI
|
|
870
849
|
is_overridable: false,
|
871
850
|
is_final: false,
|
872
851
|
allow_incompatible_override: false,
|
852
|
+
without_runtime: false,
|
873
853
|
type_params: [],
|
874
854
|
checked: nil,
|
875
855
|
loc: nil,
|
@@ -884,6 +864,7 @@ module RBI
|
|
884
864
|
@is_overridable = is_overridable
|
885
865
|
@is_final = is_final
|
886
866
|
@allow_incompatible_override = allow_incompatible_override
|
867
|
+
@without_runtime = without_runtime
|
887
868
|
@type_params = type_params
|
888
869
|
@checked = checked
|
889
870
|
block&.call(self)
|
@@ -905,7 +886,7 @@ module RBI
|
|
905
886
|
|
906
887
|
params == other.params && return_type.to_s == other.return_type.to_s && is_abstract == other.is_abstract &&
|
907
888
|
is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
|
908
|
-
type_params == other.type_params && checked == other.checked
|
889
|
+
without_runtime == other.without_runtime && type_params == other.type_params && checked == other.checked
|
909
890
|
end
|
910
891
|
end
|
911
892
|
|
@@ -940,12 +921,8 @@ module RBI
|
|
940
921
|
end
|
941
922
|
end
|
942
923
|
|
924
|
+
# @abstract
|
943
925
|
class TStructField < NodeWithComments
|
944
|
-
extend T::Sig
|
945
|
-
extend T::Helpers
|
946
|
-
|
947
|
-
abstract!
|
948
|
-
|
949
926
|
#: String
|
950
927
|
attr_accessor :name
|
951
928
|
|
@@ -963,7 +940,8 @@ module RBI
|
|
963
940
|
@default = default
|
964
941
|
end
|
965
942
|
|
966
|
-
|
943
|
+
# @abstract
|
944
|
+
#: -> Array[String]
|
967
945
|
def fully_qualified_names; end
|
968
946
|
end
|
969
947
|
|
data/lib/rbi/parser.rb
CHANGED
@@ -149,6 +149,16 @@ module RBI
|
|
149
149
|
visitor.visit(node)
|
150
150
|
visitor.location
|
151
151
|
end
|
152
|
+
|
153
|
+
#: (Prism::Node? node) -> bool
|
154
|
+
def self?(node)
|
155
|
+
node.is_a?(Prism::SelfNode)
|
156
|
+
end
|
157
|
+
|
158
|
+
#: (Prism::Node? node) -> bool
|
159
|
+
def t_sig_without_runtime?(node)
|
160
|
+
!!(node.is_a?(Prism::ConstantPathNode) && node_string(node) =~ /(::)?T::Sig::WithoutRuntime/)
|
161
|
+
end
|
152
162
|
end
|
153
163
|
|
154
164
|
class TreeBuilder < Visitor
|
@@ -370,7 +380,7 @@ module RBI
|
|
370
380
|
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
371
381
|
|
372
382
|
current_scope << AttrReader.new(
|
373
|
-
*
|
383
|
+
*args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym },
|
374
384
|
sigs: sigs,
|
375
385
|
loc: node_loc(node),
|
376
386
|
comments: comments,
|
@@ -387,7 +397,7 @@ module RBI
|
|
387
397
|
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
388
398
|
|
389
399
|
current_scope << AttrWriter.new(
|
390
|
-
*
|
400
|
+
*args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym },
|
391
401
|
sigs: sigs,
|
392
402
|
loc: node_loc(node),
|
393
403
|
comments: comments,
|
@@ -404,7 +414,7 @@ module RBI
|
|
404
414
|
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
405
415
|
|
406
416
|
current_scope << AttrAccessor.new(
|
407
|
-
*
|
417
|
+
*args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym },
|
408
418
|
sigs: sigs,
|
409
419
|
loc: node_loc(node),
|
410
420
|
comments: comments,
|
@@ -433,7 +443,7 @@ module RBI
|
|
433
443
|
end
|
434
444
|
|
435
445
|
current_scope << Extend.new(
|
436
|
-
*
|
446
|
+
*args.arguments.map { |arg| node_string!(arg) },
|
437
447
|
loc: node_loc(node),
|
438
448
|
comments: node_comments(node),
|
439
449
|
)
|
@@ -446,7 +456,7 @@ module RBI
|
|
446
456
|
end
|
447
457
|
|
448
458
|
current_scope << Include.new(
|
449
|
-
*
|
459
|
+
*args.arguments.map { |arg| node_string!(arg) },
|
450
460
|
loc: node_loc(node),
|
451
461
|
comments: node_comments(node),
|
452
462
|
)
|
@@ -459,7 +469,7 @@ module RBI
|
|
459
469
|
end
|
460
470
|
|
461
471
|
current_scope << MixesInClassMethods.new(
|
462
|
-
*
|
472
|
+
*args.arguments.map { |arg| node_string!(arg) },
|
463
473
|
loc: node_loc(node),
|
464
474
|
comments: node_comments(node),
|
465
475
|
)
|
@@ -505,6 +515,10 @@ module RBI
|
|
505
515
|
comments: node_comments(node),
|
506
516
|
)
|
507
517
|
when "sig"
|
518
|
+
unless node.receiver.nil? || self?(node.receiver) || t_sig_without_runtime?(node.receiver)
|
519
|
+
@last_node = nil
|
520
|
+
return
|
521
|
+
end
|
508
522
|
@last_sigs << parse_sig(node)
|
509
523
|
else
|
510
524
|
current_scope << Send.new(
|
@@ -593,28 +607,66 @@ module RBI
|
|
593
607
|
start_line = node.location.start_line
|
594
608
|
start_line -= 1 unless @comments_by_line.key?(start_line)
|
595
609
|
|
610
|
+
rbs_continuation = [] #: Array[Prism::Comment]
|
611
|
+
|
596
612
|
start_line.downto(1) do |line|
|
597
613
|
comment = @comments_by_line[line]
|
598
614
|
break unless comment
|
599
615
|
|
600
|
-
|
616
|
+
text = comment.location.slice
|
617
|
+
|
618
|
+
# If we find a RBS comment continuation `#|`, we store it until we find the start with `#:`
|
619
|
+
if text.start_with?("#|")
|
620
|
+
rbs_continuation << comment
|
621
|
+
@comments_by_line.delete(line)
|
622
|
+
next
|
623
|
+
end
|
624
|
+
|
625
|
+
loc = Loc.from_prism(@file, comment.location)
|
626
|
+
|
627
|
+
# If we find the start of a RBS comment, we create a new RBSComment
|
628
|
+
# Note that we ignore RDoc directives such as `:nodoc:`
|
629
|
+
# See https://ruby.github.io/rdoc/RDoc/MarkupReference.html#class-RDoc::MarkupReference-label-Directives
|
630
|
+
if text.start_with?("#:") && !(text =~ /^#:[a-z_]+:/)
|
631
|
+
text = text.sub(/^#: ?/, "").rstrip
|
632
|
+
|
633
|
+
# If we found continuation comments, we merge them in reverse order (since we go from bottom to top)
|
634
|
+
rbs_continuation.reverse_each do |rbs_comment|
|
635
|
+
continuation_text = rbs_comment.location.slice.sub(/^#\| ?/, "").strip
|
636
|
+
continuation_loc = Loc.from_prism(@file, rbs_comment.location)
|
637
|
+
loc = loc.join(continuation_loc)
|
638
|
+
text = "#{text}#{continuation_text}"
|
639
|
+
end
|
640
|
+
|
641
|
+
rbs_continuation.clear
|
642
|
+
comments.unshift(RBSComment.new(text, loc: loc))
|
643
|
+
else
|
644
|
+
# If we have unused continuation comments, we should inject them back to not lose them
|
645
|
+
rbs_continuation.each do |rbs_comment|
|
646
|
+
comments.unshift(parse_comment(rbs_comment))
|
647
|
+
end
|
648
|
+
|
649
|
+
rbs_continuation.clear
|
650
|
+
comments.unshift(parse_comment(comment))
|
651
|
+
end
|
652
|
+
|
601
653
|
@comments_by_line.delete(line)
|
602
654
|
end
|
603
655
|
|
656
|
+
# If we have unused continuation comments, we should inject them back to not lose them
|
657
|
+
rbs_continuation.each do |rbs_comment|
|
658
|
+
comments.unshift(parse_comment(rbs_comment))
|
659
|
+
end
|
660
|
+
rbs_continuation.clear
|
661
|
+
|
604
662
|
comments
|
605
663
|
end
|
606
664
|
|
607
665
|
#: (Prism::Comment node) -> Comment
|
608
666
|
def parse_comment(node)
|
667
|
+
text = node.location.slice.sub(/^# ?/, "").rstrip
|
609
668
|
loc = Loc.from_prism(@file, node.location)
|
610
|
-
|
611
|
-
# We also ignore RDoc directives such as `:nodoc:`
|
612
|
-
# See https://ruby.github.io/rdoc/RDoc/MarkupReference.html#class-RDoc::MarkupReference-label-Directives
|
613
|
-
if string.start_with?("#:") && !(string =~ /^#:[a-z_]+:/)
|
614
|
-
RBSComment.new(string.gsub(/^#: ?/, "").rstrip, loc: loc)
|
615
|
-
else
|
616
|
-
Comment.new(string.gsub(/^# ?/, "").rstrip, loc: loc)
|
617
|
-
end
|
669
|
+
Comment.new(text, loc: loc)
|
618
670
|
end
|
619
671
|
|
620
672
|
#: (Prism::Node? node) -> Array[Arg]
|
@@ -645,76 +697,68 @@ module RBI
|
|
645
697
|
|
646
698
|
#: (Prism::Node? node) -> Array[Param]
|
647
699
|
def parse_params(node)
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
node.optionals.each do |param|
|
662
|
-
next unless param.is_a?(Prism::OptionalParameterNode)
|
663
|
-
|
664
|
-
params << OptParam.new(
|
665
|
-
param.name.to_s,
|
666
|
-
node_string!(param.value),
|
667
|
-
loc: node_loc(param),
|
668
|
-
comments: node_comments(param),
|
669
|
-
)
|
670
|
-
end
|
671
|
-
|
672
|
-
rest = node.rest
|
673
|
-
if rest.is_a?(Prism::RestParameterNode)
|
674
|
-
params << RestParam.new(
|
675
|
-
rest.name&.to_s || "*args",
|
676
|
-
loc: node_loc(rest),
|
677
|
-
comments: node_comments(rest),
|
678
|
-
)
|
679
|
-
end
|
680
|
-
|
681
|
-
node.keywords.each do |param|
|
700
|
+
return [] unless node.is_a?(Prism::ParametersNode)
|
701
|
+
|
702
|
+
node_params = [
|
703
|
+
*node.requireds,
|
704
|
+
*node.optionals,
|
705
|
+
*node.rest,
|
706
|
+
*node.posts,
|
707
|
+
*node.keywords,
|
708
|
+
*node.keyword_rest,
|
709
|
+
*node.block,
|
710
|
+
].flatten
|
711
|
+
|
712
|
+
node_params.map do |param|
|
682
713
|
case param
|
714
|
+
when Prism::RequiredParameterNode
|
715
|
+
ReqParam.new(
|
716
|
+
param.name.to_s,
|
717
|
+
loc: node_loc(param),
|
718
|
+
comments: node_comments(param),
|
719
|
+
)
|
720
|
+
when Prism::OptionalParameterNode
|
721
|
+
OptParam.new(
|
722
|
+
param.name.to_s,
|
723
|
+
node_string!(param.value),
|
724
|
+
loc: node_loc(param),
|
725
|
+
comments: node_comments(param),
|
726
|
+
)
|
727
|
+
when Prism::RestParameterNode
|
728
|
+
RestParam.new(
|
729
|
+
param.name&.to_s || "*args",
|
730
|
+
loc: node_loc(param),
|
731
|
+
comments: node_comments(param),
|
732
|
+
)
|
683
733
|
when Prism::RequiredKeywordParameterNode
|
684
|
-
|
734
|
+
KwParam.new(
|
685
735
|
param.name.to_s.delete_suffix(":"),
|
686
736
|
loc: node_loc(param),
|
687
737
|
comments: node_comments(param),
|
688
738
|
)
|
689
739
|
when Prism::OptionalKeywordParameterNode
|
690
|
-
|
740
|
+
KwOptParam.new(
|
691
741
|
param.name.to_s.delete_suffix(":"),
|
692
742
|
node_string!(param.value),
|
693
743
|
loc: node_loc(param),
|
694
744
|
comments: node_comments(param),
|
695
745
|
)
|
746
|
+
when Prism::KeywordRestParameterNode
|
747
|
+
KwRestParam.new(
|
748
|
+
param.name&.to_s || "**kwargs",
|
749
|
+
loc: node_loc(param),
|
750
|
+
comments: node_comments(param),
|
751
|
+
)
|
752
|
+
when Prism::BlockParameterNode
|
753
|
+
BlockParam.new(
|
754
|
+
param.name&.to_s || "&block",
|
755
|
+
loc: node_loc(param),
|
756
|
+
comments: node_comments(param),
|
757
|
+
)
|
758
|
+
else
|
759
|
+
raise ParseError.new("Unexpected parameter node `#{param.class}`", node_loc(param))
|
696
760
|
end
|
697
761
|
end
|
698
|
-
|
699
|
-
rest_kw = node.keyword_rest
|
700
|
-
if rest_kw.is_a?(Prism::KeywordRestParameterNode)
|
701
|
-
params << KwRestParam.new(
|
702
|
-
rest_kw.name&.to_s || "**kwargs",
|
703
|
-
loc: node_loc(rest_kw),
|
704
|
-
comments: node_comments(rest_kw),
|
705
|
-
)
|
706
|
-
end
|
707
|
-
|
708
|
-
block = node.block
|
709
|
-
if block.is_a?(Prism::BlockParameterNode)
|
710
|
-
params << BlockParam.new(
|
711
|
-
block.name&.to_s || "&block",
|
712
|
-
loc: node_loc(block),
|
713
|
-
comments: node_comments(block),
|
714
|
-
)
|
715
|
-
end
|
716
|
-
|
717
|
-
params
|
718
762
|
end
|
719
763
|
|
720
764
|
#: (Prism::CallNode node) -> Sig
|
@@ -884,6 +928,8 @@ module RBI
|
|
884
928
|
def visit_call_node(node)
|
885
929
|
case node.message
|
886
930
|
when "sig"
|
931
|
+
@current.without_runtime = t_sig_without_runtime?(node.receiver)
|
932
|
+
|
887
933
|
args = node.arguments
|
888
934
|
if args.is_a?(Prism::ArgumentsNode)
|
889
935
|
args.arguments.each do |arg|
|
@@ -961,6 +1007,7 @@ module RBI
|
|
961
1007
|
@offset_last_newline = false #: bool
|
962
1008
|
end
|
963
1009
|
|
1010
|
+
# @override
|
964
1011
|
#: (Prism::StringNode node) -> void
|
965
1012
|
def visit_string_node(node)
|
966
1013
|
return unless node.heredoc?
|
@@ -971,6 +1018,7 @@ module RBI
|
|
971
1018
|
handle_string_node(node)
|
972
1019
|
end
|
973
1020
|
|
1021
|
+
# @override
|
974
1022
|
#: (Prism::InterpolatedStringNode node) -> void
|
975
1023
|
def visit_interpolated_string_node(node)
|
976
1024
|
return super unless node.heredoc?
|
data/lib/rbi/printer.rb
CHANGED
@@ -707,7 +707,9 @@ module RBI
|
|
707
707
|
|
708
708
|
#: (Sig node) -> void
|
709
709
|
def print_sig_as_line(node)
|
710
|
-
printt
|
710
|
+
printt
|
711
|
+
print("T::Sig::WithoutRuntime.") if node.without_runtime
|
712
|
+
print("sig")
|
711
713
|
print("(:final)") if node.is_final
|
712
714
|
print(" { ")
|
713
715
|
sig_modifiers(node).each do |modifier|
|
@@ -734,7 +736,9 @@ module RBI
|
|
734
736
|
def print_sig_as_block(node)
|
735
737
|
modifiers = sig_modifiers(node)
|
736
738
|
|
737
|
-
printt
|
739
|
+
printt
|
740
|
+
print("T::Sig::WithoutRuntime.") if node.without_runtime
|
741
|
+
print("sig")
|
738
742
|
print("(:final)") if node.is_final
|
739
743
|
printn(" do")
|
740
744
|
indent
|
@@ -5,35 +5,31 @@ module RBI
|
|
5
5
|
module RBS
|
6
6
|
class TypeTranslator
|
7
7
|
class << self
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
#: (NodeType) -> Type
|
8
|
+
#: (
|
9
|
+
#| ::RBS::Types::Alias |
|
10
|
+
#| ::RBS::Types::Bases::Any |
|
11
|
+
#| ::RBS::Types::Bases::Bool |
|
12
|
+
#| ::RBS::Types::Bases::Bottom |
|
13
|
+
#| ::RBS::Types::Bases::Class |
|
14
|
+
#| ::RBS::Types::Bases::Instance |
|
15
|
+
#| ::RBS::Types::Bases::Nil |
|
16
|
+
#| ::RBS::Types::Bases::Self |
|
17
|
+
#| ::RBS::Types::Bases::Top |
|
18
|
+
#| ::RBS::Types::Bases::Void |
|
19
|
+
#| ::RBS::Types::ClassSingleton |
|
20
|
+
#| ::RBS::Types::ClassInstance |
|
21
|
+
#| ::RBS::Types::Function |
|
22
|
+
#| ::RBS::Types::Interface |
|
23
|
+
#| ::RBS::Types::Intersection |
|
24
|
+
#| ::RBS::Types::Literal |
|
25
|
+
#| ::RBS::Types::Optional |
|
26
|
+
#| ::RBS::Types::Proc |
|
27
|
+
#| ::RBS::Types::Record |
|
28
|
+
#| ::RBS::Types::Tuple |
|
29
|
+
#| ::RBS::Types::Union |
|
30
|
+
#| ::RBS::Types::UntypedFunction |
|
31
|
+
#| ::RBS::Types::Variable
|
32
|
+
#| ) -> Type
|
37
33
|
def translate(type)
|
38
34
|
case type
|
39
35
|
when ::RBS::Types::Alias
|
@@ -100,7 +96,7 @@ module RBI
|
|
100
96
|
return Type.simple(type.name.to_s) if type.args.empty?
|
101
97
|
|
102
98
|
type_name = translate_t_generic_type(type.name.to_s)
|
103
|
-
|
99
|
+
Type.generic(type_name, *type.args.map { |arg| translate(arg) })
|
104
100
|
end
|
105
101
|
|
106
102
|
#: (::RBS::Types::Function) -> Type
|