rbi 0.0.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/lib/rbi/model.rb +429 -57
- data/lib/rbi/parser.rb +207 -88
- data/lib/rbi/printer.rb +148 -35
- data/lib/rbi/rewriters/add_sig_templates.rb +71 -0
- data/lib/rbi/rewriters/merge_trees.rb +50 -8
- data/lib/rbi/rewriters/nest_non_public_methods.rb +5 -5
- data/lib/rbi/rewriters/sort_nodes.rb +16 -16
- data/lib/rbi/version.rb +1 -2
- data/lib/rbi.rb +1 -0
- metadata +6 -19
data/lib/rbi/printer.rb
CHANGED
@@ -97,7 +97,7 @@ module RBI
|
|
97
97
|
v.visit_all(comments)
|
98
98
|
end
|
99
99
|
|
100
|
-
unless root.empty?
|
100
|
+
unless root.empty? && root.comments.empty?
|
101
101
|
v.printn if strictness || !comments.empty?
|
102
102
|
v.visit(root)
|
103
103
|
end
|
@@ -156,9 +156,26 @@ module RBI
|
|
156
156
|
|
157
157
|
sig { override.params(v: Printer).void }
|
158
158
|
def accept_printer(v)
|
159
|
-
|
160
|
-
|
161
|
-
|
159
|
+
lines = text.lines
|
160
|
+
|
161
|
+
if lines.empty?
|
162
|
+
v.printl("#")
|
163
|
+
end
|
164
|
+
|
165
|
+
lines.each do |line|
|
166
|
+
text = line.strip
|
167
|
+
v.printt("#")
|
168
|
+
v.print(" #{text}") unless text.empty?
|
169
|
+
v.printn
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class EmptyComment
|
175
|
+
extend T::Sig
|
176
|
+
|
177
|
+
sig { override.params(v: Printer).void }
|
178
|
+
def accept_printer(v)
|
162
179
|
v.printn
|
163
180
|
end
|
164
181
|
end
|
@@ -238,6 +255,27 @@ module RBI
|
|
238
255
|
end
|
239
256
|
end
|
240
257
|
|
258
|
+
class Struct
|
259
|
+
extend T::Sig
|
260
|
+
|
261
|
+
sig { override.params(v: Printer).void }
|
262
|
+
def print_header(v)
|
263
|
+
v.printt("#{name} = ::Struct.new")
|
264
|
+
if !members.empty? || keyword_init
|
265
|
+
v.print("(")
|
266
|
+
args = members.map { |member| ":#{member}" }
|
267
|
+
args << "keyword_init: true" if keyword_init
|
268
|
+
v.print(args.join(", "))
|
269
|
+
v.print(")")
|
270
|
+
end
|
271
|
+
if empty?
|
272
|
+
v.printn
|
273
|
+
else
|
274
|
+
v.printn(" do")
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
241
279
|
class SingletonClass
|
242
280
|
extend T::Sig
|
243
281
|
|
@@ -278,7 +316,7 @@ module RBI
|
|
278
316
|
sigs.each { |sig| v.visit(sig) }
|
279
317
|
v.printl("# #{loc}") if loc && v.print_locs
|
280
318
|
v.printt
|
281
|
-
unless v.in_visibility_group || visibility
|
319
|
+
unless v.in_visibility_group || visibility.public?
|
282
320
|
v.print(visibility.visibility.to_s)
|
283
321
|
v.print(" ")
|
284
322
|
end
|
@@ -315,7 +353,7 @@ module RBI
|
|
315
353
|
v.visit_all(sigs)
|
316
354
|
v.printl("# #{loc}") if loc && v.print_locs
|
317
355
|
v.printt
|
318
|
-
unless v.in_visibility_group || visibility
|
356
|
+
unless v.in_visibility_group || visibility.public?
|
319
357
|
v.print(visibility.visibility.to_s)
|
320
358
|
v.print(" ")
|
321
359
|
end
|
@@ -336,13 +374,14 @@ module RBI
|
|
336
374
|
v.printt
|
337
375
|
v.visit(param)
|
338
376
|
v.print(",") if pindex < params.size - 1
|
339
|
-
|
377
|
+
|
378
|
+
param.comments_lines.each_with_index do |comment, cindex|
|
340
379
|
if cindex > 0
|
341
|
-
param.print_comment_leading_space(v)
|
380
|
+
param.print_comment_leading_space(v, last: pindex == params.size - 1)
|
342
381
|
else
|
343
382
|
v.print(" ")
|
344
383
|
end
|
345
|
-
v.print("# #{comment
|
384
|
+
v.print("# #{comment}")
|
346
385
|
end
|
347
386
|
v.printn
|
348
387
|
end
|
@@ -373,11 +412,17 @@ module RBI
|
|
373
412
|
v.print(name.to_s)
|
374
413
|
end
|
375
414
|
|
376
|
-
sig { params(v: Printer).void }
|
377
|
-
def print_comment_leading_space(v)
|
415
|
+
sig { params(v: Printer, last: T::Boolean).void }
|
416
|
+
def print_comment_leading_space(v, last:)
|
378
417
|
v.printn
|
379
418
|
v.printt
|
380
|
-
v.print(" " * (name.size +
|
419
|
+
v.print(" " * (name.size + 1))
|
420
|
+
v.print(" ") unless last
|
421
|
+
end
|
422
|
+
|
423
|
+
sig { returns(T::Array[String]) }
|
424
|
+
def comments_lines
|
425
|
+
comments.flat_map { |comment| comment.text.lines.map(&:strip) }
|
381
426
|
end
|
382
427
|
end
|
383
428
|
|
@@ -389,8 +434,8 @@ module RBI
|
|
389
434
|
v.print("#{name} = #{value}")
|
390
435
|
end
|
391
436
|
|
392
|
-
sig { override.params(v: Printer).void }
|
393
|
-
def print_comment_leading_space(v)
|
437
|
+
sig { override.params(v: Printer, last: T::Boolean).void }
|
438
|
+
def print_comment_leading_space(v, last:)
|
394
439
|
super
|
395
440
|
v.print(" " * (value.size + 3))
|
396
441
|
end
|
@@ -404,8 +449,8 @@ module RBI
|
|
404
449
|
v.print("*#{name}")
|
405
450
|
end
|
406
451
|
|
407
|
-
sig { override.params(v: Printer).void }
|
408
|
-
def print_comment_leading_space(v)
|
452
|
+
sig { override.params(v: Printer, last: T::Boolean).void }
|
453
|
+
def print_comment_leading_space(v, last:)
|
409
454
|
super
|
410
455
|
v.print(" ")
|
411
456
|
end
|
@@ -419,8 +464,8 @@ module RBI
|
|
419
464
|
v.print("#{name}:")
|
420
465
|
end
|
421
466
|
|
422
|
-
sig { override.params(v: Printer).void }
|
423
|
-
def print_comment_leading_space(v)
|
467
|
+
sig { override.params(v: Printer, last: T::Boolean).void }
|
468
|
+
def print_comment_leading_space(v, last:)
|
424
469
|
super
|
425
470
|
v.print(" ")
|
426
471
|
end
|
@@ -434,11 +479,9 @@ module RBI
|
|
434
479
|
v.print("#{name}: #{value}")
|
435
480
|
end
|
436
481
|
|
437
|
-
sig { override.params(v: Printer).void }
|
438
|
-
def print_comment_leading_space(v)
|
439
|
-
|
440
|
-
v.printt
|
441
|
-
v.print(" " * (name.size + 2))
|
482
|
+
sig { override.params(v: Printer, last: T::Boolean).void }
|
483
|
+
def print_comment_leading_space(v, last:)
|
484
|
+
super
|
442
485
|
v.print(" " * (value.size + 2))
|
443
486
|
end
|
444
487
|
end
|
@@ -451,8 +494,8 @@ module RBI
|
|
451
494
|
v.print("**#{name}")
|
452
495
|
end
|
453
496
|
|
454
|
-
sig { override.params(v: Printer).void }
|
455
|
-
def print_comment_leading_space(v)
|
497
|
+
sig { override.params(v: Printer, last: T::Boolean).void }
|
498
|
+
def print_comment_leading_space(v, last:)
|
456
499
|
super
|
457
500
|
v.print(" ")
|
458
501
|
end
|
@@ -465,6 +508,12 @@ module RBI
|
|
465
508
|
def accept_printer(v)
|
466
509
|
v.print("&#{name}")
|
467
510
|
end
|
511
|
+
|
512
|
+
sig { override.params(v: Printer, last: T::Boolean).void }
|
513
|
+
def print_comment_leading_space(v, last:)
|
514
|
+
super
|
515
|
+
v.print(" ")
|
516
|
+
end
|
468
517
|
end
|
469
518
|
|
470
519
|
class Mixin
|
@@ -494,7 +543,11 @@ module RBI
|
|
494
543
|
|
495
544
|
sig { override.params(v: Printer).void }
|
496
545
|
def accept_printer(v)
|
546
|
+
previous_node = v.previous_node
|
547
|
+
v.printn if previous_node && (!previous_node.oneline? || !oneline?)
|
548
|
+
|
497
549
|
v.printl("# #{loc}") if loc && v.print_locs
|
550
|
+
v.visit_all(comments)
|
498
551
|
v.printl(visibility.to_s)
|
499
552
|
end
|
500
553
|
end
|
@@ -505,7 +558,12 @@ module RBI
|
|
505
558
|
sig { override.params(v: Printer).void }
|
506
559
|
def accept_printer(v)
|
507
560
|
v.printl("# #{loc}") if loc && v.print_locs
|
508
|
-
|
561
|
+
if oneline?
|
562
|
+
v.printt("sig { ")
|
563
|
+
else
|
564
|
+
v.printl("sig do")
|
565
|
+
v.indent
|
566
|
+
end
|
509
567
|
v.print("abstract.") if is_abstract
|
510
568
|
v.print("override.") if is_override
|
511
569
|
v.print("overridable.") if is_overridable
|
@@ -518,12 +576,33 @@ module RBI
|
|
518
576
|
v.print(").")
|
519
577
|
end
|
520
578
|
unless params.empty?
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
579
|
+
if inline_params?
|
580
|
+
v.print("params(")
|
581
|
+
params.each_with_index do |param, index|
|
582
|
+
v.print(", ") if index > 0
|
583
|
+
v.visit(param)
|
584
|
+
end
|
585
|
+
v.print(").")
|
586
|
+
else
|
587
|
+
v.printl("params(")
|
588
|
+
v.indent
|
589
|
+
params.each_with_index do |param, pindex|
|
590
|
+
v.printt
|
591
|
+
v.visit(param)
|
592
|
+
v.print(",") if pindex < params.size - 1
|
593
|
+
param.comments_lines.each_with_index do |comment, cindex|
|
594
|
+
if cindex == 0
|
595
|
+
v.print(" ")
|
596
|
+
else
|
597
|
+
param.print_comment_leading_space(v, last: pindex == params.size - 1)
|
598
|
+
end
|
599
|
+
v.print("# #{comment}")
|
600
|
+
end
|
601
|
+
v.printn
|
602
|
+
end
|
603
|
+
v.dedent
|
604
|
+
v.printt(").")
|
525
605
|
end
|
526
|
-
v.print(").")
|
527
606
|
end
|
528
607
|
if return_type && return_type != "void"
|
529
608
|
v.print("returns(#{return_type})")
|
@@ -533,7 +612,23 @@ module RBI
|
|
533
612
|
if checked
|
534
613
|
v.print(".checked(:#{checked})")
|
535
614
|
end
|
536
|
-
|
615
|
+
if oneline?
|
616
|
+
v.printn(" }")
|
617
|
+
else
|
618
|
+
v.printn
|
619
|
+
v.dedent
|
620
|
+
v.printl("end")
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
sig { override.returns(T::Boolean) }
|
625
|
+
def oneline?
|
626
|
+
inline_params?
|
627
|
+
end
|
628
|
+
|
629
|
+
sig { returns(T::Boolean) }
|
630
|
+
def inline_params?
|
631
|
+
params.all? { |p| p.comments.empty? }
|
537
632
|
end
|
538
633
|
end
|
539
634
|
|
@@ -544,6 +639,19 @@ module RBI
|
|
544
639
|
def accept_printer(v)
|
545
640
|
v.print("#{name}: #{type}")
|
546
641
|
end
|
642
|
+
|
643
|
+
sig { params(v: Printer, last: T::Boolean).void }
|
644
|
+
def print_comment_leading_space(v, last:)
|
645
|
+
v.printn
|
646
|
+
v.printt
|
647
|
+
v.print(" " * (name.size + type.size + 3))
|
648
|
+
v.print(" ") unless last
|
649
|
+
end
|
650
|
+
|
651
|
+
sig { returns(T::Array[String]) }
|
652
|
+
def comments_lines
|
653
|
+
comments.flat_map { |comment| comment.text.lines.map(&:strip) }
|
654
|
+
end
|
547
655
|
end
|
548
656
|
|
549
657
|
class TStructField
|
@@ -630,14 +738,19 @@ module RBI
|
|
630
738
|
sig { override.params(v: Printer).void }
|
631
739
|
def accept_printer(v)
|
632
740
|
v.in_visibility_group = true
|
633
|
-
|
634
|
-
|
635
|
-
|
741
|
+
if visibility.public?
|
742
|
+
v.printn unless v.previous_node.nil?
|
743
|
+
else
|
636
744
|
v.visit(visibility)
|
637
745
|
v.printn
|
638
746
|
end
|
639
747
|
v.visit_all(nodes)
|
640
748
|
v.in_visibility_group = false
|
641
749
|
end
|
750
|
+
|
751
|
+
sig { override.returns(T::Boolean) }
|
752
|
+
def oneline?
|
753
|
+
false
|
754
|
+
end
|
642
755
|
end
|
643
756
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RBI
|
5
|
+
module Rewriters
|
6
|
+
class AddSigTemplates < Visitor
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { params(with_todo_comment: T::Boolean).void }
|
10
|
+
def initialize(with_todo_comment: true)
|
11
|
+
super()
|
12
|
+
@with_todo_comment = with_todo_comment
|
13
|
+
end
|
14
|
+
|
15
|
+
sig { override.params(node: T.nilable(Node)).void }
|
16
|
+
def visit(node)
|
17
|
+
case node
|
18
|
+
when Tree
|
19
|
+
visit_all(node.nodes)
|
20
|
+
when Attr
|
21
|
+
add_attr_sig(node)
|
22
|
+
when Method
|
23
|
+
add_method_sig(node)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
sig { params(attr: Attr).void }
|
30
|
+
def add_attr_sig(attr)
|
31
|
+
return unless attr.sigs.empty?
|
32
|
+
return if attr.names.size > 1
|
33
|
+
|
34
|
+
params = []
|
35
|
+
params << SigParam.new(attr.names.first.to_s, "T.untyped") if attr.is_a?(AttrWriter)
|
36
|
+
|
37
|
+
attr.sigs << Sig.new(
|
38
|
+
params: params,
|
39
|
+
return_type: "T.untyped"
|
40
|
+
)
|
41
|
+
add_todo_comment(attr)
|
42
|
+
end
|
43
|
+
|
44
|
+
sig { params(method: Method).void }
|
45
|
+
def add_method_sig(method)
|
46
|
+
return unless method.sigs.empty?
|
47
|
+
|
48
|
+
method.sigs << Sig.new(
|
49
|
+
params: method.params.map { |param| SigParam.new(param.name, "T.untyped") },
|
50
|
+
return_type: "T.untyped"
|
51
|
+
)
|
52
|
+
add_todo_comment(method)
|
53
|
+
end
|
54
|
+
|
55
|
+
sig { params(node: NodeWithComments).void }
|
56
|
+
def add_todo_comment(node)
|
57
|
+
node.comments << Comment.new("TODO: fill in signature with appropriate type information") if @with_todo_comment
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Tree
|
63
|
+
extend T::Sig
|
64
|
+
|
65
|
+
sig { params(with_todo_comment: T::Boolean).void }
|
66
|
+
def add_sig_templates!(with_todo_comment: true)
|
67
|
+
visitor = Rewriters::AddSigTemplates.new(with_todo_comment: with_todo_comment)
|
68
|
+
visitor.visit(self)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -39,9 +39,19 @@ module RBI
|
|
39
39
|
class Merge
|
40
40
|
extend T::Sig
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
class Keep < ::T::Enum
|
43
|
+
enums do
|
44
|
+
NONE = new
|
45
|
+
LEFT = new
|
46
|
+
RIGHT = new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
sig { params(left: Tree, right: Tree, left_name: String, right_name: String, keep: Keep).returns(Tree) }
|
51
|
+
def self.merge_trees(left, right, left_name: "left", right_name: "right", keep: Keep::NONE)
|
52
|
+
left.nest_singleton_methods!
|
53
|
+
right.nest_singleton_methods!
|
54
|
+
rewriter = Rewriters::Merge.new(left_name: left_name, right_name: right_name, keep: keep)
|
45
55
|
rewriter.merge(left)
|
46
56
|
rewriter.merge(right)
|
47
57
|
tree = rewriter.tree
|
@@ -52,17 +62,18 @@ module RBI
|
|
52
62
|
sig { returns(Tree) }
|
53
63
|
attr_reader :tree
|
54
64
|
|
55
|
-
sig { params(left_name: String, right_name: String).void }
|
56
|
-
def initialize(left_name: "left", right_name: "right")
|
65
|
+
sig { params(left_name: String, right_name: String, keep: Keep).void }
|
66
|
+
def initialize(left_name: "left", right_name: "right", keep: Keep::NONE)
|
57
67
|
@left_name = left_name
|
58
68
|
@right_name = right_name
|
69
|
+
@keep = keep
|
59
70
|
@tree = T.let(Tree.new, Tree)
|
60
71
|
@scope_stack = T.let([@tree], T::Array[Tree])
|
61
72
|
end
|
62
73
|
|
63
74
|
sig { params(tree: Tree).returns(T::Array[Conflict]) }
|
64
75
|
def merge(tree)
|
65
|
-
v = TreeMerger.new(@tree, left_name: @left_name, right_name: @right_name)
|
76
|
+
v = TreeMerger.new(@tree, left_name: @left_name, right_name: @right_name, keep: @keep)
|
66
77
|
v.visit(tree)
|
67
78
|
v.conflicts
|
68
79
|
end
|
@@ -88,14 +99,15 @@ module RBI
|
|
88
99
|
sig { returns(T::Array[Conflict]) }
|
89
100
|
attr_reader :conflicts
|
90
101
|
|
91
|
-
sig { params(output: Tree, left_name: String, right_name: String).void }
|
92
|
-
def initialize(output, left_name: "left", right_name: "right")
|
102
|
+
sig { params(output: Tree, left_name: String, right_name: String, keep: Keep).void }
|
103
|
+
def initialize(output, left_name: "left", right_name: "right", keep: Keep::NONE)
|
93
104
|
super()
|
94
105
|
@tree = output
|
95
106
|
@index = T.let(output.index, Index)
|
96
107
|
@scope_stack = T.let([@tree], T::Array[Tree])
|
97
108
|
@left_name = left_name
|
98
109
|
@right_name = right_name
|
110
|
+
@keep = keep
|
99
111
|
@conflicts = T.let([], T::Array[Conflict])
|
100
112
|
end
|
101
113
|
|
@@ -110,6 +122,10 @@ module RBI
|
|
110
122
|
if prev.is_a?(Scope)
|
111
123
|
if node.compatible_with?(prev)
|
112
124
|
prev.merge_with(node)
|
125
|
+
elsif @keep == Keep::LEFT
|
126
|
+
# do nothing it's already merged
|
127
|
+
elsif @keep == Keep::RIGHT
|
128
|
+
prev = replace_scope_header(prev, node)
|
113
129
|
else
|
114
130
|
make_conflict_scope(prev, node)
|
115
131
|
end
|
@@ -129,6 +145,10 @@ module RBI
|
|
129
145
|
if prev
|
130
146
|
if node.compatible_with?(prev)
|
131
147
|
prev.merge_with(node)
|
148
|
+
elsif @keep == Keep::LEFT
|
149
|
+
# do nothing it's already merged
|
150
|
+
elsif @keep == Keep::RIGHT
|
151
|
+
prev.replace(node)
|
132
152
|
else
|
133
153
|
make_conflict_tree(prev, node)
|
134
154
|
end
|
@@ -175,6 +195,17 @@ module RBI
|
|
175
195
|
end
|
176
196
|
tree.right << right
|
177
197
|
end
|
198
|
+
|
199
|
+
sig { params(left: Scope, right: Scope).returns(Scope) }
|
200
|
+
def replace_scope_header(left, right)
|
201
|
+
right_copy = right.dup_empty
|
202
|
+
left.replace(right_copy)
|
203
|
+
left.nodes.each do |node|
|
204
|
+
right_copy << node
|
205
|
+
end
|
206
|
+
@index.index(right_copy)
|
207
|
+
right_copy
|
208
|
+
end
|
178
209
|
end
|
179
210
|
|
180
211
|
# Merge adjacent conflict trees
|
@@ -300,6 +331,8 @@ module RBI
|
|
300
331
|
Module.new(name, loc: loc, comments: comments)
|
301
332
|
when Class
|
302
333
|
Class.new(name, superclass_name: superclass_name, loc: loc, comments: comments)
|
334
|
+
when Struct
|
335
|
+
Struct.new(name, members: members, keyword_init: keyword_init, loc: loc, comments: comments)
|
303
336
|
when SingletonClass
|
304
337
|
SingletonClass.new(loc: loc, comments: comments)
|
305
338
|
else
|
@@ -326,6 +359,15 @@ module RBI
|
|
326
359
|
end
|
327
360
|
end
|
328
361
|
|
362
|
+
class Struct
|
363
|
+
extend T::Sig
|
364
|
+
|
365
|
+
sig { override.params(other: Node).returns(T::Boolean) }
|
366
|
+
def compatible_with?(other)
|
367
|
+
other.is_a?(Struct) && members == other.members && keyword_init == other.keyword_init
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
329
371
|
class Const
|
330
372
|
extend T::Sig
|
331
373
|
|
@@ -12,18 +12,18 @@ module RBI
|
|
12
12
|
|
13
13
|
case node
|
14
14
|
when Tree
|
15
|
-
public_group = VisibilityGroup.new(
|
16
|
-
protected_group = VisibilityGroup.new(
|
17
|
-
private_group = VisibilityGroup.new(
|
15
|
+
public_group = VisibilityGroup.new(Public.new)
|
16
|
+
protected_group = VisibilityGroup.new(Protected.new)
|
17
|
+
private_group = VisibilityGroup.new(Private.new)
|
18
18
|
|
19
19
|
node.nodes.dup.each do |child|
|
20
20
|
visit(child)
|
21
21
|
next unless child.is_a?(Method)
|
22
22
|
child.detach
|
23
23
|
case child.visibility
|
24
|
-
when
|
24
|
+
when Protected
|
25
25
|
protected_group << child
|
26
|
-
when
|
26
|
+
when Private
|
27
27
|
private_group << child
|
28
28
|
else
|
29
29
|
public_group << child
|
@@ -10,11 +10,11 @@ module RBI
|
|
10
10
|
def visit(node)
|
11
11
|
return unless node.is_a?(Tree)
|
12
12
|
visit_all(node.nodes)
|
13
|
+
original_order = node.nodes.map.with_index.to_h
|
13
14
|
node.nodes.sort! do |a, b|
|
14
|
-
return 0 if a.is_a?(Mixin) || b.is_a?(Mixin)
|
15
|
-
|
16
15
|
res = node_rank(a) <=> node_rank(b)
|
17
16
|
res = node_name(a) <=> node_name(b) if res == 0
|
17
|
+
res = (original_order[a] || 0) <=> (original_order[b] || 0) if res == 0
|
18
18
|
res || 0
|
19
19
|
end
|
20
20
|
end
|
@@ -24,29 +24,29 @@ module RBI
|
|
24
24
|
sig { params(node: Node).returns(Integer) }
|
25
25
|
def node_rank(node)
|
26
26
|
case node
|
27
|
-
when Group then
|
28
|
-
when Include, Extend then
|
29
|
-
when Helper then
|
30
|
-
when TypeMember then
|
31
|
-
when MixesInClassMethods then
|
32
|
-
when TStructField then
|
33
|
-
when TEnumBlock then
|
27
|
+
when Group then group_rank(node.kind)
|
28
|
+
when Include, Extend then 10
|
29
|
+
when Helper then 20
|
30
|
+
when TypeMember then 30
|
31
|
+
when MixesInClassMethods then 40
|
32
|
+
when TStructField then 50
|
33
|
+
when TEnumBlock then 60
|
34
34
|
when Method
|
35
35
|
if node.name == "initialize"
|
36
|
-
|
36
|
+
71
|
37
37
|
elsif !node.is_singleton
|
38
|
-
|
38
|
+
72
|
39
39
|
else
|
40
|
-
|
40
|
+
73
|
41
41
|
end
|
42
|
-
when Scope, Const then
|
42
|
+
when Scope, Const then 80
|
43
43
|
else
|
44
|
-
|
44
|
+
100
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
sig { params(kind: Group::Kind).returns(Integer) }
|
49
|
-
def
|
49
|
+
def group_rank(kind)
|
50
50
|
case kind
|
51
51
|
when Group::Kind::Mixins then 0
|
52
52
|
when Group::Kind::Helpers then 1
|
@@ -65,7 +65,7 @@ module RBI
|
|
65
65
|
sig { params(node: Node).returns(T.nilable(String)) }
|
66
66
|
def node_name(node)
|
67
67
|
case node
|
68
|
-
when Module, Class, Const, Method, Helper, TStructField
|
68
|
+
when Module, Class, Struct, Const, Method, Helper, TStructField
|
69
69
|
node.name
|
70
70
|
end
|
71
71
|
end
|
data/lib/rbi/version.rb
CHANGED
data/lib/rbi.rb
CHANGED
@@ -12,6 +12,7 @@ require "rbi/loc"
|
|
12
12
|
require "rbi/model"
|
13
13
|
require "rbi/visitor"
|
14
14
|
require "rbi/index"
|
15
|
+
require "rbi/rewriters/add_sig_templates"
|
15
16
|
require "rbi/rewriters/merge_trees"
|
16
17
|
require "rbi/rewriters/nest_singleton_methods"
|
17
18
|
require "rbi/rewriters/nest_non_public_methods"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -38,34 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '13.0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '13.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: sorbet-runtime
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: 0.5.9204
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: 0.5.9204
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: unparser
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +68,7 @@ dependencies:
|
|
82
68
|
version: '0'
|
83
69
|
description:
|
84
70
|
email:
|
85
|
-
-
|
71
|
+
- ruby@shopify.com
|
86
72
|
executables: []
|
87
73
|
extensions: []
|
88
74
|
extra_rdoc_files: []
|
@@ -96,6 +82,7 @@ files:
|
|
96
82
|
- lib/rbi/model.rb
|
97
83
|
- lib/rbi/parser.rb
|
98
84
|
- lib/rbi/printer.rb
|
85
|
+
- lib/rbi/rewriters/add_sig_templates.rb
|
99
86
|
- lib/rbi/rewriters/group_nodes.rb
|
100
87
|
- lib/rbi/rewriters/merge_trees.rb
|
101
88
|
- lib/rbi/rewriters/nest_non_public_methods.rb
|