rbi 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbi/loc.rb +6 -6
- data/lib/rbi/parser.rb +136 -89
- data/lib/rbi/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3adefb9fc887432fdab8f11a5800c58fe0c4b7a089c1170d67fc5fa6374c475d
|
4
|
+
data.tar.gz: 5259d5132a2b83761a22419c10fca4beff9bb95e2e60c779c3e7b5583230476d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb345c63c449eb4610d826b3a9a2e6da4633ac7f29ceaf0b46af689f956d5a6758939d02b6234f676c6f7ce6f49ccf119e4a6237946e87cd9a7d13b57f014f82
|
7
|
+
data.tar.gz: 674a6fe4acf7b92ea718ed12c0906d5d1b8a1e1942869e0c163060fd107d227a65e0eb58460d694f22c48f3809c37739033a3b806551676ac136fedc360b0750
|
data/lib/rbi/loc.rb
CHANGED
@@ -8,14 +8,14 @@ module RBI
|
|
8
8
|
class << self
|
9
9
|
extend T::Sig
|
10
10
|
|
11
|
-
sig { params(file: String,
|
12
|
-
def
|
11
|
+
sig { params(file: String, prism_location: Prism::Location).returns(Loc) }
|
12
|
+
def from_prism(file, prism_location)
|
13
13
|
new(
|
14
14
|
file: file,
|
15
|
-
begin_line:
|
16
|
-
end_line:
|
17
|
-
begin_column:
|
18
|
-
end_column:
|
15
|
+
begin_line: prism_location.start_line,
|
16
|
+
end_line: prism_location.end_line,
|
17
|
+
begin_column: prism_location.start_column,
|
18
|
+
end_column: prism_location.end_column,
|
19
19
|
)
|
20
20
|
end
|
21
21
|
end
|
data/lib/rbi/parser.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "
|
4
|
+
require "prism"
|
5
5
|
|
6
6
|
module RBI
|
7
7
|
class ParseError < StandardError
|
@@ -93,7 +93,7 @@ module RBI
|
|
93
93
|
|
94
94
|
sig { params(source: String, file: String).returns(Tree) }
|
95
95
|
def parse(source, file:)
|
96
|
-
result =
|
96
|
+
result = Prism.parse(source)
|
97
97
|
unless result.success?
|
98
98
|
message = result.errors.map { |e| "#{e.message}." }.join(" ")
|
99
99
|
error = result.errors.first
|
@@ -104,14 +104,12 @@ module RBI
|
|
104
104
|
visitor = TreeBuilder.new(source, comments: result.comments, file: file)
|
105
105
|
visitor.visit(result.value)
|
106
106
|
visitor.tree
|
107
|
-
rescue YARP::ParseError => e
|
108
|
-
raise ParseError.new(e.message, Loc.from_yarp(file, e.location))
|
109
107
|
rescue ParseError => e
|
110
108
|
raise e
|
111
109
|
rescue => e
|
112
110
|
last_node = visitor&.last_node
|
113
111
|
last_location = if last_node
|
114
|
-
Loc.
|
112
|
+
Loc.from_prism(file, last_node.location)
|
115
113
|
else
|
116
114
|
Loc.new(file: file)
|
117
115
|
end
|
@@ -121,7 +119,7 @@ module RBI
|
|
121
119
|
raise exception
|
122
120
|
end
|
123
121
|
|
124
|
-
class Visitor <
|
122
|
+
class Visitor < Prism::Visitor
|
125
123
|
extend T::Sig
|
126
124
|
|
127
125
|
sig { params(source: String, file: String).void }
|
@@ -134,19 +132,19 @@ module RBI
|
|
134
132
|
|
135
133
|
private
|
136
134
|
|
137
|
-
sig { params(node:
|
135
|
+
sig { params(node: Prism::Node).returns(Loc) }
|
138
136
|
def node_loc(node)
|
139
|
-
Loc.
|
137
|
+
Loc.from_prism(@file, node.location)
|
140
138
|
end
|
141
139
|
|
142
|
-
sig { params(node: T.nilable(
|
140
|
+
sig { params(node: T.nilable(Prism::Node)).returns(T.nilable(String)) }
|
143
141
|
def node_string(node)
|
144
142
|
return unless node
|
145
143
|
|
146
144
|
node.slice
|
147
145
|
end
|
148
146
|
|
149
|
-
sig { params(node:
|
147
|
+
sig { params(node: Prism::Node).returns(String) }
|
150
148
|
def node_string!(node)
|
151
149
|
T.must(node_string(node))
|
152
150
|
end
|
@@ -158,32 +156,25 @@ module RBI
|
|
158
156
|
sig { returns(Tree) }
|
159
157
|
attr_reader :tree
|
160
158
|
|
161
|
-
sig { returns(T.nilable(
|
159
|
+
sig { returns(T.nilable(Prism::Node)) }
|
162
160
|
attr_reader :last_node
|
163
161
|
|
164
|
-
sig { params(source: String, comments: T::Array[
|
162
|
+
sig { params(source: String, comments: T::Array[Prism::Comment], file: String).void }
|
165
163
|
def initialize(source, comments:, file:)
|
166
164
|
super(source, file: file)
|
167
165
|
|
168
|
-
@comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer,
|
166
|
+
@comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer, Prism::Comment])
|
169
167
|
@tree = T.let(Tree.new, Tree)
|
170
168
|
|
171
169
|
@scopes_stack = T.let([@tree], T::Array[Tree])
|
172
|
-
@last_node = T.let(nil, T.nilable(
|
170
|
+
@last_node = T.let(nil, T.nilable(Prism::Node))
|
173
171
|
@last_sigs = T.let([], T::Array[RBI::Sig])
|
174
172
|
@last_sigs_comments = T.let([], T::Array[Comment])
|
175
173
|
end
|
176
174
|
|
177
|
-
sig { override.params(node:
|
178
|
-
def visit(node)
|
179
|
-
return unless node
|
180
|
-
|
181
|
-
@last_node = node
|
182
|
-
super
|
183
|
-
end
|
184
|
-
|
185
|
-
sig { override.params(node: YARP::ClassNode).void }
|
175
|
+
sig { override.params(node: Prism::ClassNode).void }
|
186
176
|
def visit_class_node(node)
|
177
|
+
@last_node = node
|
187
178
|
scope = Class.new(
|
188
179
|
node_string!(node.constant_path),
|
189
180
|
superclass_name: node_string(node.superclass),
|
@@ -196,19 +187,24 @@ module RBI
|
|
196
187
|
visit(node.body)
|
197
188
|
collect_dangling_comments(node)
|
198
189
|
@scopes_stack.pop
|
190
|
+
@last_node = nil
|
199
191
|
end
|
200
192
|
|
201
|
-
sig { override.params(node:
|
193
|
+
sig { override.params(node: Prism::ConstantWriteNode).void }
|
202
194
|
def visit_constant_write_node(node)
|
195
|
+
@last_node = node
|
203
196
|
visit_constant_assign(node)
|
197
|
+
@last_node = nil
|
204
198
|
end
|
205
199
|
|
206
|
-
sig { override.params(node:
|
200
|
+
sig { override.params(node: Prism::ConstantPathWriteNode).void }
|
207
201
|
def visit_constant_path_write_node(node)
|
202
|
+
@last_node = node
|
208
203
|
visit_constant_assign(node)
|
204
|
+
@last_node = nil
|
209
205
|
end
|
210
206
|
|
211
|
-
sig { params(node: T.any(
|
207
|
+
sig { params(node: T.any(Prism::ConstantWriteNode, Prism::ConstantPathWriteNode)).void }
|
212
208
|
def visit_constant_assign(node)
|
213
209
|
struct = parse_struct(node)
|
214
210
|
|
@@ -217,9 +213,9 @@ module RBI
|
|
217
213
|
elsif type_variable_definition?(node.value)
|
218
214
|
TypeMember.new(
|
219
215
|
case node
|
220
|
-
when
|
216
|
+
when Prism::ConstantWriteNode
|
221
217
|
node.name.to_s
|
222
|
-
when
|
218
|
+
when Prism::ConstantPathWriteNode
|
223
219
|
node_string!(node.target)
|
224
220
|
end,
|
225
221
|
node_string!(node.value),
|
@@ -229,9 +225,9 @@ module RBI
|
|
229
225
|
else
|
230
226
|
Const.new(
|
231
227
|
case node
|
232
|
-
when
|
228
|
+
when Prism::ConstantWriteNode
|
233
229
|
node.name.to_s
|
234
|
-
when
|
230
|
+
when Prism::ConstantPathWriteNode
|
235
231
|
node_string!(node.target)
|
236
232
|
end,
|
237
233
|
node_string!(node.value),
|
@@ -241,8 +237,9 @@ module RBI
|
|
241
237
|
end
|
242
238
|
end
|
243
239
|
|
244
|
-
sig { override.params(node:
|
240
|
+
sig { override.params(node: Prism::DefNode).void }
|
245
241
|
def visit_def_node(node)
|
242
|
+
@last_node = node
|
246
243
|
current_scope << Method.new(
|
247
244
|
node.name.to_s,
|
248
245
|
params: parse_params(node.parameters),
|
@@ -251,10 +248,12 @@ module RBI
|
|
251
248
|
comments: current_sigs_comments + node_comments(node),
|
252
249
|
is_singleton: !!node.receiver,
|
253
250
|
)
|
251
|
+
@last_node = nil
|
254
252
|
end
|
255
253
|
|
256
|
-
sig { override.params(node:
|
254
|
+
sig { override.params(node: Prism::ModuleNode).void }
|
257
255
|
def visit_module_node(node)
|
256
|
+
@last_node = node
|
258
257
|
scope = Module.new(
|
259
258
|
node_string!(node.constant_path),
|
260
259
|
loc: node_loc(node),
|
@@ -266,19 +265,23 @@ module RBI
|
|
266
265
|
visit(node.body)
|
267
266
|
collect_dangling_comments(node)
|
268
267
|
@scopes_stack.pop
|
268
|
+
@last_node = nil
|
269
269
|
end
|
270
270
|
|
271
|
-
sig { override.params(node:
|
271
|
+
sig { override.params(node: Prism::ProgramNode).void }
|
272
272
|
def visit_program_node(node)
|
273
|
+
@last_node = node
|
273
274
|
super
|
274
275
|
|
275
276
|
collect_orphan_comments
|
276
277
|
separate_header_comments
|
277
278
|
set_root_tree_loc
|
279
|
+
@last_node = nil
|
278
280
|
end
|
279
281
|
|
280
|
-
sig { override.params(node:
|
282
|
+
sig { override.params(node: Prism::SingletonClassNode).void }
|
281
283
|
def visit_singleton_class_node(node)
|
284
|
+
@last_node = node
|
282
285
|
scope = SingletonClass.new(
|
283
286
|
loc: node_loc(node),
|
284
287
|
comments: node_comments(node),
|
@@ -289,11 +292,13 @@ module RBI
|
|
289
292
|
visit(node.body)
|
290
293
|
collect_dangling_comments(node)
|
291
294
|
@scopes_stack.pop
|
295
|
+
@last_node = nil
|
292
296
|
end
|
293
297
|
|
294
|
-
sig { params(node:
|
298
|
+
sig { params(node: Prism::CallNode).void }
|
295
299
|
def visit_call_node(node)
|
296
|
-
|
300
|
+
@last_node = node
|
301
|
+
message = node.name.to_s
|
297
302
|
case message
|
298
303
|
when "abstract!", "sealed!", "interface!"
|
299
304
|
current_scope << Helper.new(
|
@@ -303,7 +308,11 @@ module RBI
|
|
303
308
|
)
|
304
309
|
when "attr_reader"
|
305
310
|
args = node.arguments
|
306
|
-
|
311
|
+
|
312
|
+
unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
313
|
+
@last_node = nil
|
314
|
+
return
|
315
|
+
end
|
307
316
|
|
308
317
|
current_scope << AttrReader.new(
|
309
318
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
|
@@ -313,7 +322,11 @@ module RBI
|
|
313
322
|
)
|
314
323
|
when "attr_writer"
|
315
324
|
args = node.arguments
|
316
|
-
|
325
|
+
|
326
|
+
unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
327
|
+
@last_node = nil
|
328
|
+
return
|
329
|
+
end
|
317
330
|
|
318
331
|
current_scope << AttrWriter.new(
|
319
332
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
|
@@ -323,7 +336,11 @@ module RBI
|
|
323
336
|
)
|
324
337
|
when "attr_accessor"
|
325
338
|
args = node.arguments
|
326
|
-
|
339
|
+
|
340
|
+
unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
341
|
+
@last_node = nil
|
342
|
+
return
|
343
|
+
end
|
327
344
|
|
328
345
|
current_scope << AttrAccessor.new(
|
329
346
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
|
@@ -333,19 +350,31 @@ module RBI
|
|
333
350
|
)
|
334
351
|
when "enums"
|
335
352
|
block = node.block
|
336
|
-
|
353
|
+
|
354
|
+
unless block.is_a?(Prism::BlockNode)
|
355
|
+
@last_node = nil
|
356
|
+
return
|
357
|
+
end
|
337
358
|
|
338
359
|
body = block.body
|
339
|
-
|
360
|
+
|
361
|
+
unless body.is_a?(Prism::StatementsNode)
|
362
|
+
@last_node = nil
|
363
|
+
return
|
364
|
+
end
|
340
365
|
|
341
366
|
current_scope << TEnumBlock.new(
|
342
|
-
body.body.map { |stmt| T.cast(stmt,
|
367
|
+
body.body.map { |stmt| T.cast(stmt, Prism::ConstantWriteNode).name.to_s },
|
343
368
|
loc: node_loc(node),
|
344
369
|
comments: node_comments(node),
|
345
370
|
)
|
346
371
|
when "extend"
|
347
372
|
args = node.arguments
|
348
|
-
|
373
|
+
|
374
|
+
unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
375
|
+
@last_node = nil
|
376
|
+
return
|
377
|
+
end
|
349
378
|
|
350
379
|
current_scope << Extend.new(
|
351
380
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
|
@@ -354,7 +383,11 @@ module RBI
|
|
354
383
|
)
|
355
384
|
when "include"
|
356
385
|
args = node.arguments
|
357
|
-
|
386
|
+
|
387
|
+
unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
388
|
+
@last_node = nil
|
389
|
+
return
|
390
|
+
end
|
358
391
|
|
359
392
|
current_scope << Include.new(
|
360
393
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
|
@@ -363,7 +396,11 @@ module RBI
|
|
363
396
|
)
|
364
397
|
when "mixes_in_class_methods"
|
365
398
|
args = node.arguments
|
366
|
-
|
399
|
+
|
400
|
+
unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
401
|
+
@last_node = nil
|
402
|
+
return
|
403
|
+
end
|
367
404
|
|
368
405
|
current_scope << MixesInClassMethods.new(
|
369
406
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
|
@@ -372,12 +409,12 @@ module RBI
|
|
372
409
|
)
|
373
410
|
when "private", "protected", "public"
|
374
411
|
args = node.arguments
|
375
|
-
if args.is_a?(
|
412
|
+
if args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
|
376
413
|
visit(node.arguments)
|
377
414
|
last_node = @scopes_stack.last&.nodes&.last
|
378
415
|
case last_node
|
379
416
|
when Method, Attr
|
380
|
-
last_node.visibility = parse_visibility(node.name, node)
|
417
|
+
last_node.visibility = parse_visibility(node.name.to_s, node)
|
381
418
|
else
|
382
419
|
raise ParseError.new(
|
383
420
|
"Unexpected token `#{node.message}` before `#{last_node&.string&.strip}`",
|
@@ -385,16 +422,24 @@ module RBI
|
|
385
422
|
)
|
386
423
|
end
|
387
424
|
else
|
388
|
-
current_scope << parse_visibility(node.name, node)
|
425
|
+
current_scope << parse_visibility(node.name.to_s, node)
|
389
426
|
end
|
390
427
|
when "prop", "const"
|
391
428
|
parse_tstruct_field(node)
|
392
429
|
when "requires_ancestor"
|
393
430
|
block = node.block
|
394
|
-
|
431
|
+
|
432
|
+
unless block.is_a?(Prism::BlockNode)
|
433
|
+
@last_node = nil
|
434
|
+
return
|
435
|
+
end
|
395
436
|
|
396
437
|
body = block.body
|
397
|
-
|
438
|
+
|
439
|
+
unless body.is_a?(Prism::StatementsNode)
|
440
|
+
@last_node = nil
|
441
|
+
return
|
442
|
+
end
|
398
443
|
|
399
444
|
current_scope << RequiresAncestor.new(
|
400
445
|
node_string!(body),
|
@@ -411,12 +456,14 @@ module RBI
|
|
411
456
|
comments: node_comments(node),
|
412
457
|
)
|
413
458
|
end
|
459
|
+
|
460
|
+
@last_node = nil
|
414
461
|
end
|
415
462
|
|
416
463
|
private
|
417
464
|
|
418
465
|
# Collect all the remaining comments within a node
|
419
|
-
sig { params(node:
|
466
|
+
sig { params(node: Prism::Node).void }
|
420
467
|
def collect_dangling_comments(node)
|
421
468
|
first_line = node.location.start_line
|
422
469
|
last_line = node.location.end_line
|
@@ -449,7 +496,7 @@ module RBI
|
|
449
496
|
|
450
497
|
# Preserve blank lines in comments
|
451
498
|
if last_line && line > last_line + 1
|
452
|
-
recv << BlankLine.new(loc: Loc.
|
499
|
+
recv << BlankLine.new(loc: Loc.from_prism(@file, comment.location))
|
453
500
|
end
|
454
501
|
|
455
502
|
recv << parse_comment(comment)
|
@@ -476,7 +523,7 @@ module RBI
|
|
476
523
|
comments
|
477
524
|
end
|
478
525
|
|
479
|
-
sig { params(node:
|
526
|
+
sig { params(node: Prism::Node).returns(T::Array[Comment]) }
|
480
527
|
def node_comments(node)
|
481
528
|
comments = []
|
482
529
|
|
@@ -494,21 +541,21 @@ module RBI
|
|
494
541
|
comments
|
495
542
|
end
|
496
543
|
|
497
|
-
sig { params(node:
|
544
|
+
sig { params(node: Prism::Comment).returns(Comment) }
|
498
545
|
def parse_comment(node)
|
499
|
-
Comment.new(node.location.slice.gsub(/^# ?/, "").rstrip, loc: Loc.
|
546
|
+
Comment.new(node.location.slice.gsub(/^# ?/, "").rstrip, loc: Loc.from_prism(@file, node.location))
|
500
547
|
end
|
501
548
|
|
502
|
-
sig { params(node: T.nilable(
|
549
|
+
sig { params(node: T.nilable(Prism::Node)).returns(T::Array[Arg]) }
|
503
550
|
def parse_send_args(node)
|
504
551
|
args = T.let([], T::Array[Arg])
|
505
|
-
return args unless node.is_a?(
|
552
|
+
return args unless node.is_a?(Prism::ArgumentsNode)
|
506
553
|
|
507
554
|
node.arguments.each do |arg|
|
508
555
|
case arg
|
509
|
-
when
|
556
|
+
when Prism::KeywordHashNode
|
510
557
|
arg.elements.each do |assoc|
|
511
|
-
next unless assoc.is_a?(
|
558
|
+
next unless assoc.is_a?(Prism::AssocNode)
|
512
559
|
|
513
560
|
args << KwArg.new(
|
514
561
|
node_string!(assoc.key).delete_suffix(":"),
|
@@ -523,13 +570,13 @@ module RBI
|
|
523
570
|
args
|
524
571
|
end
|
525
572
|
|
526
|
-
sig { params(node: T.nilable(
|
573
|
+
sig { params(node: T.nilable(Prism::Node)).returns(T::Array[Param]) }
|
527
574
|
def parse_params(node)
|
528
575
|
params = []
|
529
|
-
return params unless node.is_a?(
|
576
|
+
return params unless node.is_a?(Prism::ParametersNode)
|
530
577
|
|
531
578
|
node.requireds.each do |param|
|
532
|
-
next unless param.is_a?(
|
579
|
+
next unless param.is_a?(Prism::RequiredParameterNode)
|
533
580
|
|
534
581
|
params << ReqParam.new(
|
535
582
|
param.name.to_s,
|
@@ -539,7 +586,7 @@ module RBI
|
|
539
586
|
end
|
540
587
|
|
541
588
|
node.optionals.each do |param|
|
542
|
-
next unless param.is_a?(
|
589
|
+
next unless param.is_a?(Prism::OptionalParameterNode)
|
543
590
|
|
544
591
|
params << OptParam.new(
|
545
592
|
param.name.to_s,
|
@@ -550,7 +597,7 @@ module RBI
|
|
550
597
|
end
|
551
598
|
|
552
599
|
rest = node.rest
|
553
|
-
if rest.is_a?(
|
600
|
+
if rest.is_a?(Prism::RestParameterNode)
|
554
601
|
params << RestParam.new(
|
555
602
|
rest.name&.to_s || "*args",
|
556
603
|
loc: node_loc(rest),
|
@@ -559,7 +606,7 @@ module RBI
|
|
559
606
|
end
|
560
607
|
|
561
608
|
node.keywords.each do |param|
|
562
|
-
next unless param.is_a?(
|
609
|
+
next unless param.is_a?(Prism::KeywordParameterNode)
|
563
610
|
|
564
611
|
value = param.value
|
565
612
|
params << if value
|
@@ -579,7 +626,7 @@ module RBI
|
|
579
626
|
end
|
580
627
|
|
581
628
|
rest_kw = node.keyword_rest
|
582
|
-
if rest_kw.is_a?(
|
629
|
+
if rest_kw.is_a?(Prism::KeywordRestParameterNode)
|
583
630
|
params << KwRestParam.new(
|
584
631
|
rest_kw.name&.to_s || "**kwargs",
|
585
632
|
loc: node_loc(rest_kw),
|
@@ -588,7 +635,7 @@ module RBI
|
|
588
635
|
end
|
589
636
|
|
590
637
|
block = node.block
|
591
|
-
if block.is_a?(
|
638
|
+
if block.is_a?(Prism::BlockParameterNode)
|
592
639
|
params << BlockParam.new(
|
593
640
|
block.name&.to_s || "&block",
|
594
641
|
loc: node_loc(block),
|
@@ -599,7 +646,7 @@ module RBI
|
|
599
646
|
params
|
600
647
|
end
|
601
648
|
|
602
|
-
sig { params(node:
|
649
|
+
sig { params(node: Prism::CallNode).returns(Sig) }
|
603
650
|
def parse_sig(node)
|
604
651
|
@last_sigs_comments = node_comments(node)
|
605
652
|
|
@@ -609,10 +656,10 @@ module RBI
|
|
609
656
|
builder.current
|
610
657
|
end
|
611
658
|
|
612
|
-
sig { params(node: T.any(
|
659
|
+
sig { params(node: T.any(Prism::ConstantWriteNode, Prism::ConstantPathWriteNode)).returns(T.nilable(Struct)) }
|
613
660
|
def parse_struct(node)
|
614
661
|
send = node.value
|
615
|
-
return unless send.is_a?(
|
662
|
+
return unless send.is_a?(Prism::CallNode)
|
616
663
|
return unless send.message == "new"
|
617
664
|
|
618
665
|
recv = send.receiver
|
@@ -623,14 +670,14 @@ module RBI
|
|
623
670
|
keyword_init = T.let(false, T::Boolean)
|
624
671
|
|
625
672
|
args = send.arguments
|
626
|
-
if args.is_a?(
|
673
|
+
if args.is_a?(Prism::ArgumentsNode)
|
627
674
|
args.arguments.each do |arg|
|
628
675
|
case arg
|
629
|
-
when
|
676
|
+
when Prism::SymbolNode
|
630
677
|
members << arg.value
|
631
|
-
when
|
678
|
+
when Prism::KeywordHashNode
|
632
679
|
arg.elements.each do |assoc|
|
633
|
-
next unless assoc.is_a?(
|
680
|
+
next unless assoc.is_a?(Prism::AssocNode)
|
634
681
|
|
635
682
|
key = node_string!(assoc.key)
|
636
683
|
val = node_string(assoc.value)
|
@@ -644,9 +691,9 @@ module RBI
|
|
644
691
|
end
|
645
692
|
|
646
693
|
name = case node
|
647
|
-
when
|
694
|
+
when Prism::ConstantWriteNode
|
648
695
|
node.name.to_s
|
649
|
-
when
|
696
|
+
when Prism::ConstantPathWriteNode
|
650
697
|
node_string!(node.target)
|
651
698
|
end
|
652
699
|
|
@@ -659,10 +706,10 @@ module RBI
|
|
659
706
|
struct
|
660
707
|
end
|
661
708
|
|
662
|
-
sig { params(send:
|
709
|
+
sig { params(send: Prism::CallNode).void }
|
663
710
|
def parse_tstruct_field(send)
|
664
711
|
args = send.arguments
|
665
|
-
return unless args.is_a?(
|
712
|
+
return unless args.is_a?(Prism::ArgumentsNode)
|
666
713
|
|
667
714
|
name_arg, type_arg, *rest = args.arguments
|
668
715
|
return unless name_arg
|
@@ -675,10 +722,10 @@ module RBI
|
|
675
722
|
default_value = T.let(nil, T.nilable(String))
|
676
723
|
|
677
724
|
rest&.each do |arg|
|
678
|
-
next unless arg.is_a?(
|
725
|
+
next unless arg.is_a?(Prism::KeywordHashNode)
|
679
726
|
|
680
727
|
arg.elements.each do |assoc|
|
681
|
-
next unless assoc.is_a?(
|
728
|
+
next unless assoc.is_a?(Prism::AssocNode)
|
682
729
|
|
683
730
|
if node_string(assoc.key) == "default:"
|
684
731
|
default_value = node_string(assoc.value)
|
@@ -696,7 +743,7 @@ module RBI
|
|
696
743
|
end
|
697
744
|
end
|
698
745
|
|
699
|
-
sig { params(name: String, node:
|
746
|
+
sig { params(name: String, node: Prism::Node).returns(Visibility) }
|
700
747
|
def parse_visibility(name, node)
|
701
748
|
case name
|
702
749
|
when "public"
|
@@ -734,9 +781,9 @@ module RBI
|
|
734
781
|
)
|
735
782
|
end
|
736
783
|
|
737
|
-
sig { params(node: T.nilable(
|
784
|
+
sig { params(node: T.nilable(Prism::Node)).returns(T::Boolean) }
|
738
785
|
def type_variable_definition?(node)
|
739
|
-
return false unless node.is_a?(
|
786
|
+
return false unless node.is_a?(Prism::CallNode)
|
740
787
|
return false unless node.block
|
741
788
|
|
742
789
|
node.message == "type_member" || node.message == "type_template"
|
@@ -756,12 +803,12 @@ module RBI
|
|
756
803
|
@current = T.let(Sig.new, Sig)
|
757
804
|
end
|
758
805
|
|
759
|
-
sig { override.params(node:
|
806
|
+
sig { override.params(node: Prism::CallNode).void }
|
760
807
|
def visit_call_node(node)
|
761
808
|
case node.message
|
762
809
|
when "sig"
|
763
810
|
args = node.arguments
|
764
|
-
if args.is_a?(
|
811
|
+
if args.is_a?(Prism::ArgumentsNode)
|
765
812
|
args.arguments.each do |arg|
|
766
813
|
@current.is_final = node_string(arg) == ":final"
|
767
814
|
end
|
@@ -770,7 +817,7 @@ module RBI
|
|
770
817
|
@current.is_abstract = true
|
771
818
|
when "checked"
|
772
819
|
args = node.arguments
|
773
|
-
if args.is_a?(
|
820
|
+
if args.is_a?(Prism::ArgumentsNode)
|
774
821
|
arg = node_string(args.arguments.first)
|
775
822
|
@current.checked = arg&.delete_prefix(":")&.to_sym
|
776
823
|
end
|
@@ -782,13 +829,13 @@ module RBI
|
|
782
829
|
visit(node.arguments)
|
783
830
|
when "returns"
|
784
831
|
args = node.arguments
|
785
|
-
if args.is_a?(
|
832
|
+
if args.is_a?(Prism::ArgumentsNode)
|
786
833
|
first = args.arguments.first
|
787
834
|
@current.return_type = node_string!(first) if first
|
788
835
|
end
|
789
836
|
when "type_parameters"
|
790
837
|
args = node.arguments
|
791
|
-
if args.is_a?(
|
838
|
+
if args.is_a?(Prism::ArgumentsNode)
|
792
839
|
args.arguments.each do |arg|
|
793
840
|
@current.type_params << node_string!(arg).delete_prefix(":")
|
794
841
|
end
|
@@ -801,7 +848,7 @@ module RBI
|
|
801
848
|
visit(node.block)
|
802
849
|
end
|
803
850
|
|
804
|
-
sig { override.params(node:
|
851
|
+
sig { override.params(node: Prism::AssocNode).void }
|
805
852
|
def visit_assoc_node(node)
|
806
853
|
@current.params << SigParam.new(
|
807
854
|
node_string!(node.key).delete_suffix(":"),
|
data/lib/rbi/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: prism
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.15.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.15.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sorbet-runtime
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.5.9204
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.5.9204
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- ruby@shopify.com
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
rubygems_version: 3.4.
|
89
|
+
rubygems_version: 3.4.21
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: RBI generation framework
|