rbi 0.1.13 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/rbi/formatter.rb +4 -16
- data/lib/rbi/index.rb +1 -1
- data/lib/rbi/model.rb +38 -36
- data/lib/rbi/parser.rb +90 -53
- data/lib/rbi/printer.rb +512 -611
- data/lib/rbi/rewriters/attr_to_methods.rb +169 -0
- data/lib/rbi/rewriters/flatten_singleton_methods.rb +65 -0
- data/lib/rbi/rewriters/flatten_visibilities.rb +65 -0
- data/lib/rbi/rewriters/group_nodes.rb +46 -47
- data/lib/rbi/rewriters/merge_trees.rb +15 -45
- data/lib/rbi/rewriters/{nest_non_public_methods.rb → nest_non_public_members.rb} +4 -4
- data/lib/rbi/rewriters/nest_top_level_members.rb +68 -0
- data/lib/rbi/type.rb +765 -0
- data/lib/rbi/type_parser.rb +320 -0
- data/lib/rbi/type_visitor.rb +112 -0
- data/lib/rbi/version.rb +1 -1
- data/lib/rbi/visitor.rb +228 -2
- data/lib/rbi.rb +15 -1
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bcb914ddfe3208193a252f650ac6bcbc25c741efa183d28876ad1f0957cd24f
|
4
|
+
data.tar.gz: db2f129f6925c498e6112e43a7fc44b9a4a6aeb694cd18e97e64e3531bfe7ae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0def2a8d159eba09b59cbd403126a4b198687f018c65acec3d35cfa978d25da1bc97956ccb2d017d81ece08fe8e1f65e06b0ed4968b60fcb3b3e4b5cb497cdfe
|
7
|
+
data.tar.gz: 7f065932016677c397967f1dc16ca5115d8279ec65d00962e850496f616c16f76954e334611a66132cdeeea889866f5c41ffd2089ee5f9cdf473d77211cbfd80
|
data/Gemfile
CHANGED
@@ -10,9 +10,9 @@ group(:development, :test) do
|
|
10
10
|
gem("minitest")
|
11
11
|
gem("minitest-reporters")
|
12
12
|
gem("rake", "~> 13.2")
|
13
|
-
gem("rubocop", "~> 1.
|
13
|
+
gem("rubocop", "~> 1.65", 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)
|
17
|
-
gem("tapioca", require: false)
|
17
|
+
gem("tapioca", github: "Shopify/tapioca", branch: "at-bump-rbi", require: false)
|
18
18
|
end
|
data/lib/rbi/formatter.rb
CHANGED
@@ -8,18 +8,6 @@ module RBI
|
|
8
8
|
sig { params(sort_nodes: T::Boolean).returns(T::Boolean) }
|
9
9
|
attr_writer :sort_nodes
|
10
10
|
|
11
|
-
sig { params(nest_singleton_methods: T::Boolean).returns(T::Boolean) }
|
12
|
-
attr_writer :nest_singleton_methods
|
13
|
-
|
14
|
-
sig { params(add_sig_templates: T::Boolean).returns(T::Boolean) }
|
15
|
-
attr_writer :add_sig_templates
|
16
|
-
|
17
|
-
sig { params(group_nodes: T::Boolean).returns(T::Boolean) }
|
18
|
-
attr_writer :group_nodes
|
19
|
-
|
20
|
-
sig { params(nest_non_public_methods: T::Boolean).returns(T::Boolean) }
|
21
|
-
attr_writer :nest_non_public_methods
|
22
|
-
|
23
11
|
sig { returns(T.nilable(Integer)) }
|
24
12
|
attr_accessor :max_line_length
|
25
13
|
|
@@ -29,7 +17,7 @@ module RBI
|
|
29
17
|
group_nodes: T::Boolean,
|
30
18
|
max_line_length: T.nilable(Integer),
|
31
19
|
nest_singleton_methods: T::Boolean,
|
32
|
-
|
20
|
+
nest_non_public_members: T::Boolean,
|
33
21
|
sort_nodes: T::Boolean,
|
34
22
|
).void
|
35
23
|
end
|
@@ -38,14 +26,14 @@ module RBI
|
|
38
26
|
group_nodes: false,
|
39
27
|
max_line_length: nil,
|
40
28
|
nest_singleton_methods: false,
|
41
|
-
|
29
|
+
nest_non_public_members: false,
|
42
30
|
sort_nodes: false
|
43
31
|
)
|
44
32
|
@add_sig_templates = add_sig_templates
|
45
33
|
@group_nodes = group_nodes
|
46
34
|
@max_line_length = max_line_length
|
47
35
|
@nest_singleton_methods = nest_singleton_methods
|
48
|
-
@
|
36
|
+
@nest_non_public_members = nest_non_public_members
|
49
37
|
@sort_nodes = sort_nodes
|
50
38
|
end
|
51
39
|
|
@@ -64,7 +52,7 @@ module RBI
|
|
64
52
|
def format_tree(tree)
|
65
53
|
tree.add_sig_templates! if @add_sig_templates
|
66
54
|
tree.nest_singleton_methods! if @nest_singleton_methods
|
67
|
-
tree.
|
55
|
+
tree.nest_non_public_members! if @nest_non_public_members
|
68
56
|
tree.group_nodes! if @group_nodes
|
69
57
|
tree.sort_nodes! if @sort_nodes
|
70
58
|
end
|
data/lib/rbi/index.rb
CHANGED
data/lib/rbi/model.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module RBI
|
5
|
+
class ReplaceNodeError < Error; end
|
6
|
+
|
5
7
|
class Node
|
6
8
|
extend T::Sig
|
7
9
|
extend T::Helpers
|
@@ -32,10 +34,10 @@ module RBI
|
|
32
34
|
sig { params(node: Node).void }
|
33
35
|
def replace(node)
|
34
36
|
tree = parent_tree
|
35
|
-
raise unless tree
|
37
|
+
raise ReplaceNodeError, "Can't replace #{self} without a parent tree" unless tree
|
36
38
|
|
37
39
|
index = tree.nodes.index(self)
|
38
|
-
raise unless index
|
40
|
+
raise ReplaceNodeError, "Can't find #{self} in #{tree} child nodes" unless index
|
39
41
|
|
40
42
|
tree.nodes[index] = node
|
41
43
|
node.parent_tree = tree
|
@@ -572,7 +574,7 @@ module RBI
|
|
572
574
|
sig do
|
573
575
|
params(
|
574
576
|
params: T::Array[SigParam],
|
575
|
-
return_type: T.
|
577
|
+
return_type: T.any(String, Type),
|
576
578
|
is_abstract: T::Boolean,
|
577
579
|
is_override: T::Boolean,
|
578
580
|
is_overridable: T::Boolean,
|
@@ -584,7 +586,7 @@ module RBI
|
|
584
586
|
end
|
585
587
|
def add_sig(
|
586
588
|
params: [],
|
587
|
-
return_type:
|
589
|
+
return_type: "void",
|
588
590
|
is_abstract: false,
|
589
591
|
is_override: false,
|
590
592
|
is_overridable: false,
|
@@ -926,8 +928,10 @@ module RBI
|
|
926
928
|
@visibility = visibility
|
927
929
|
end
|
928
930
|
|
929
|
-
sig { params(other:
|
931
|
+
sig { params(other: T.nilable(Object)).returns(T::Boolean) }
|
930
932
|
def ==(other)
|
933
|
+
return false unless other.is_a?(Visibility)
|
934
|
+
|
931
935
|
visibility == other.visibility
|
932
936
|
end
|
933
937
|
|
@@ -1097,13 +1101,13 @@ module RBI
|
|
1097
1101
|
|
1098
1102
|
# Sorbet's sigs
|
1099
1103
|
|
1100
|
-
class Sig <
|
1104
|
+
class Sig < NodeWithComments
|
1101
1105
|
extend T::Sig
|
1102
1106
|
|
1103
1107
|
sig { returns(T::Array[SigParam]) }
|
1104
1108
|
attr_reader :params
|
1105
1109
|
|
1106
|
-
sig { returns(T.
|
1110
|
+
sig { returns(T.any(Type, String)) }
|
1107
1111
|
attr_accessor :return_type
|
1108
1112
|
|
1109
1113
|
sig { returns(T::Boolean) }
|
@@ -1118,7 +1122,7 @@ module RBI
|
|
1118
1122
|
sig do
|
1119
1123
|
params(
|
1120
1124
|
params: T::Array[SigParam],
|
1121
|
-
return_type: T.
|
1125
|
+
return_type: T.any(Type, String),
|
1122
1126
|
is_abstract: T::Boolean,
|
1123
1127
|
is_override: T::Boolean,
|
1124
1128
|
is_overridable: T::Boolean,
|
@@ -1126,12 +1130,13 @@ module RBI
|
|
1126
1130
|
type_params: T::Array[String],
|
1127
1131
|
checked: T.nilable(Symbol),
|
1128
1132
|
loc: T.nilable(Loc),
|
1133
|
+
comments: T::Array[Comment],
|
1129
1134
|
block: T.nilable(T.proc.params(node: Sig).void),
|
1130
1135
|
).void
|
1131
1136
|
end
|
1132
1137
|
def initialize(
|
1133
1138
|
params: [],
|
1134
|
-
return_type:
|
1139
|
+
return_type: "void",
|
1135
1140
|
is_abstract: false,
|
1136
1141
|
is_override: false,
|
1137
1142
|
is_overridable: false,
|
@@ -1139,9 +1144,10 @@ module RBI
|
|
1139
1144
|
type_params: [],
|
1140
1145
|
checked: nil,
|
1141
1146
|
loc: nil,
|
1147
|
+
comments: [],
|
1142
1148
|
&block
|
1143
1149
|
)
|
1144
|
-
super(loc: loc)
|
1150
|
+
super(loc: loc, comments: comments)
|
1145
1151
|
@params = params
|
1146
1152
|
@return_type = return_type
|
1147
1153
|
@is_abstract = is_abstract
|
@@ -1158,7 +1164,7 @@ module RBI
|
|
1158
1164
|
@params << param
|
1159
1165
|
end
|
1160
1166
|
|
1161
|
-
sig { params(name: String, type: String).void }
|
1167
|
+
sig { params(name: String, type: T.any(Type, String)).void }
|
1162
1168
|
def add_param(name, type)
|
1163
1169
|
@params << SigParam.new(name, type)
|
1164
1170
|
end
|
@@ -1167,7 +1173,7 @@ module RBI
|
|
1167
1173
|
def ==(other)
|
1168
1174
|
return false unless other.is_a?(Sig)
|
1169
1175
|
|
1170
|
-
params == other.params && return_type == other.return_type && is_abstract == other.is_abstract &&
|
1176
|
+
params == other.params && return_type.to_s == other.return_type.to_s && is_abstract == other.is_abstract &&
|
1171
1177
|
is_override == other.is_override && is_overridable == other.is_overridable && is_final == other.is_final &&
|
1172
1178
|
type_params == other.type_params && checked == other.checked
|
1173
1179
|
end
|
@@ -1177,12 +1183,15 @@ module RBI
|
|
1177
1183
|
extend T::Sig
|
1178
1184
|
|
1179
1185
|
sig { returns(String) }
|
1180
|
-
attr_reader :name
|
1186
|
+
attr_reader :name
|
1187
|
+
|
1188
|
+
sig { returns(T.any(Type, String)) }
|
1189
|
+
attr_reader :type
|
1181
1190
|
|
1182
1191
|
sig do
|
1183
1192
|
params(
|
1184
1193
|
name: String,
|
1185
|
-
type: String,
|
1194
|
+
type: T.any(Type, String),
|
1186
1195
|
loc: T.nilable(Loc),
|
1187
1196
|
comments: T::Array[Comment],
|
1188
1197
|
block: T.nilable(T.proc.params(node: SigParam).void),
|
@@ -1197,7 +1206,7 @@ module RBI
|
|
1197
1206
|
|
1198
1207
|
sig { params(other: Object).returns(T::Boolean) }
|
1199
1208
|
def ==(other)
|
1200
|
-
other.is_a?(SigParam) && name == other.name && type == other.type
|
1209
|
+
other.is_a?(SigParam) && name == other.name && type.to_s == other.type.to_s
|
1201
1210
|
end
|
1202
1211
|
end
|
1203
1212
|
|
@@ -1227,7 +1236,10 @@ module RBI
|
|
1227
1236
|
abstract!
|
1228
1237
|
|
1229
1238
|
sig { returns(String) }
|
1230
|
-
attr_accessor :name
|
1239
|
+
attr_accessor :name
|
1240
|
+
|
1241
|
+
sig { returns(T.any(Type, String)) }
|
1242
|
+
attr_accessor :type
|
1231
1243
|
|
1232
1244
|
sig { returns(T.nilable(String)) }
|
1233
1245
|
attr_accessor :default
|
@@ -1235,7 +1247,7 @@ module RBI
|
|
1235
1247
|
sig do
|
1236
1248
|
params(
|
1237
1249
|
name: String,
|
1238
|
-
type: String,
|
1250
|
+
type: T.any(Type, String),
|
1239
1251
|
default: T.nilable(String),
|
1240
1252
|
loc: T.nilable(Loc),
|
1241
1253
|
comments: T::Array[Comment],
|
@@ -1258,7 +1270,7 @@ module RBI
|
|
1258
1270
|
sig do
|
1259
1271
|
params(
|
1260
1272
|
name: String,
|
1261
|
-
type: String,
|
1273
|
+
type: T.any(Type, String),
|
1262
1274
|
default: T.nilable(String),
|
1263
1275
|
loc: T.nilable(Loc),
|
1264
1276
|
comments: T::Array[Comment],
|
@@ -1288,7 +1300,7 @@ module RBI
|
|
1288
1300
|
sig do
|
1289
1301
|
params(
|
1290
1302
|
name: String,
|
1291
|
-
type: String,
|
1303
|
+
type: T.any(Type, String),
|
1292
1304
|
default: T.nilable(String),
|
1293
1305
|
loc: T.nilable(Loc),
|
1294
1306
|
comments: T::Array[Comment],
|
@@ -1331,39 +1343,29 @@ module RBI
|
|
1331
1343
|
end
|
1332
1344
|
end
|
1333
1345
|
|
1334
|
-
class TEnumBlock <
|
1346
|
+
class TEnumBlock < Scope
|
1335
1347
|
extend T::Sig
|
1336
1348
|
|
1337
|
-
sig { returns(T::Array[String]) }
|
1338
|
-
attr_reader :names
|
1339
|
-
|
1340
1349
|
sig do
|
1341
1350
|
params(
|
1342
|
-
names: T::Array[String],
|
1343
1351
|
loc: T.nilable(Loc),
|
1344
1352
|
comments: T::Array[Comment],
|
1345
1353
|
block: T.nilable(T.proc.params(node: TEnumBlock).void),
|
1346
1354
|
).void
|
1347
1355
|
end
|
1348
|
-
def initialize(
|
1349
|
-
super(loc: loc, comments: comments)
|
1350
|
-
@names = names
|
1356
|
+
def initialize(loc: nil, comments: [], &block)
|
1357
|
+
super(loc: loc, comments: comments) {}
|
1351
1358
|
block&.call(self)
|
1352
1359
|
end
|
1353
1360
|
|
1354
|
-
sig { returns(
|
1355
|
-
def
|
1356
|
-
|
1357
|
-
end
|
1358
|
-
|
1359
|
-
sig { params(name: String).void }
|
1360
|
-
def <<(name)
|
1361
|
-
@names << name
|
1361
|
+
sig { override.returns(String) }
|
1362
|
+
def fully_qualified_name
|
1363
|
+
"#{parent_scope&.fully_qualified_name}.enums"
|
1362
1364
|
end
|
1363
1365
|
|
1364
1366
|
sig { override.returns(String) }
|
1365
1367
|
def to_s
|
1366
|
-
|
1368
|
+
fully_qualified_name
|
1367
1369
|
end
|
1368
1370
|
end
|
1369
1371
|
|
data/lib/rbi/parser.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require "prism"
|
5
5
|
|
6
6
|
module RBI
|
7
|
-
class ParseError <
|
7
|
+
class ParseError < Error
|
8
8
|
extend T::Sig
|
9
9
|
|
10
10
|
sig { returns(Loc) }
|
@@ -17,7 +17,7 @@ module RBI
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
class UnexpectedParserError <
|
20
|
+
class UnexpectedParserError < Error
|
21
21
|
extend T::Sig
|
22
22
|
|
23
23
|
sig { returns(Loc) }
|
@@ -169,22 +169,38 @@ module RBI
|
|
169
169
|
@scopes_stack = T.let([@tree], T::Array[Tree])
|
170
170
|
@last_node = T.let(nil, T.nilable(Prism::Node))
|
171
171
|
@last_sigs = T.let([], T::Array[RBI::Sig])
|
172
|
-
@last_sigs_comments = T.let([], T::Array[Comment])
|
173
172
|
end
|
174
173
|
|
175
174
|
sig { override.params(node: Prism::ClassNode).void }
|
176
175
|
def visit_class_node(node)
|
177
176
|
@last_node = node
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
177
|
+
superclass_name = node_string(node.superclass)
|
178
|
+
scope = case superclass_name
|
179
|
+
when /^(::)?T::Struct$/
|
180
|
+
TStruct.new(
|
181
|
+
node_string!(node.constant_path),
|
182
|
+
loc: node_loc(node),
|
183
|
+
comments: node_comments(node),
|
184
|
+
)
|
185
|
+
when /^(::)?T::Enum$/
|
186
|
+
TEnum.new(
|
187
|
+
node_string!(node.constant_path),
|
188
|
+
loc: node_loc(node),
|
189
|
+
comments: node_comments(node),
|
190
|
+
)
|
191
|
+
else
|
192
|
+
Class.new(
|
193
|
+
node_string!(node.constant_path),
|
194
|
+
superclass_name: superclass_name,
|
195
|
+
loc: node_loc(node),
|
196
|
+
comments: node_comments(node),
|
197
|
+
)
|
198
|
+
end
|
184
199
|
|
185
200
|
current_scope << scope
|
186
201
|
@scopes_stack << scope
|
187
202
|
visit(node.body)
|
203
|
+
scope.nodes.concat(current_sigs)
|
188
204
|
collect_dangling_comments(node)
|
189
205
|
@scopes_stack.pop
|
190
206
|
@last_node = nil
|
@@ -240,12 +256,19 @@ module RBI
|
|
240
256
|
sig { override.params(node: Prism::DefNode).void }
|
241
257
|
def visit_def_node(node)
|
242
258
|
@last_node = node
|
259
|
+
|
260
|
+
# We need to collect the comments with `current_sigs_comments` _before_ visiting the parameters to make sure
|
261
|
+
# the method comments are properly associated with the sigs and not the parameters.
|
262
|
+
sigs = current_sigs
|
263
|
+
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
264
|
+
params = parse_params(node.parameters)
|
265
|
+
|
243
266
|
current_scope << Method.new(
|
244
267
|
node.name.to_s,
|
245
|
-
params:
|
246
|
-
sigs:
|
268
|
+
params: params,
|
269
|
+
sigs: sigs,
|
247
270
|
loc: node_loc(node),
|
248
|
-
comments:
|
271
|
+
comments: comments,
|
249
272
|
is_singleton: !!node.receiver,
|
250
273
|
)
|
251
274
|
@last_node = nil
|
@@ -263,6 +286,7 @@ module RBI
|
|
263
286
|
current_scope << scope
|
264
287
|
@scopes_stack << scope
|
265
288
|
visit(node.body)
|
289
|
+
scope.nodes.concat(current_sigs)
|
266
290
|
collect_dangling_comments(node)
|
267
291
|
@scopes_stack.pop
|
268
292
|
@last_node = nil
|
@@ -272,7 +296,7 @@ module RBI
|
|
272
296
|
def visit_program_node(node)
|
273
297
|
@last_node = node
|
274
298
|
super
|
275
|
-
|
299
|
+
@tree.nodes.concat(current_sigs)
|
276
300
|
collect_orphan_comments
|
277
301
|
separate_header_comments
|
278
302
|
set_root_tree_loc
|
@@ -290,6 +314,7 @@ module RBI
|
|
290
314
|
current_scope << scope
|
291
315
|
@scopes_stack << scope
|
292
316
|
visit(node.body)
|
317
|
+
scope.nodes.concat(current_sigs)
|
293
318
|
collect_dangling_comments(node)
|
294
319
|
@scopes_stack.pop
|
295
320
|
@last_node = nil
|
@@ -314,11 +339,14 @@ module RBI
|
|
314
339
|
return
|
315
340
|
end
|
316
341
|
|
342
|
+
sigs = current_sigs
|
343
|
+
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
344
|
+
|
317
345
|
current_scope << AttrReader.new(
|
318
346
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
|
319
|
-
sigs:
|
347
|
+
sigs: sigs,
|
320
348
|
loc: node_loc(node),
|
321
|
-
comments:
|
349
|
+
comments: comments,
|
322
350
|
)
|
323
351
|
when "attr_writer"
|
324
352
|
args = node.arguments
|
@@ -328,11 +356,14 @@ module RBI
|
|
328
356
|
return
|
329
357
|
end
|
330
358
|
|
359
|
+
sigs = current_sigs
|
360
|
+
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
361
|
+
|
331
362
|
current_scope << AttrWriter.new(
|
332
363
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
|
333
|
-
sigs:
|
364
|
+
sigs: sigs,
|
334
365
|
loc: node_loc(node),
|
335
|
-
comments:
|
366
|
+
comments: comments,
|
336
367
|
)
|
337
368
|
when "attr_accessor"
|
338
369
|
args = node.arguments
|
@@ -342,32 +373,30 @@ module RBI
|
|
342
373
|
return
|
343
374
|
end
|
344
375
|
|
376
|
+
sigs = current_sigs
|
377
|
+
comments = detach_comments_from_sigs(sigs) + node_comments(node)
|
378
|
+
|
345
379
|
current_scope << AttrAccessor.new(
|
346
380
|
*T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
|
347
|
-
sigs:
|
381
|
+
sigs: sigs,
|
348
382
|
loc: node_loc(node),
|
349
|
-
comments:
|
383
|
+
comments: comments,
|
350
384
|
)
|
351
385
|
when "enums"
|
352
|
-
block
|
353
|
-
|
354
|
-
|
355
|
-
@
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
386
|
+
if node.block && node.arguments.nil?
|
387
|
+
scope = TEnumBlock.new(loc: node_loc(node), comments: node_comments(node))
|
388
|
+
current_scope << scope
|
389
|
+
@scopes_stack << scope
|
390
|
+
visit(node.block)
|
391
|
+
@scopes_stack.pop
|
392
|
+
else
|
393
|
+
current_scope << Send.new(
|
394
|
+
message,
|
395
|
+
parse_send_args(node.arguments),
|
396
|
+
loc: node_loc(node),
|
397
|
+
comments: node_comments(node),
|
398
|
+
)
|
364
399
|
end
|
365
|
-
|
366
|
-
current_scope << TEnumBlock.new(
|
367
|
-
body.body.map { |stmt| T.cast(stmt, Prism::ConstantWriteNode).name.to_s },
|
368
|
-
loc: node_loc(node),
|
369
|
-
comments: node_comments(node),
|
370
|
-
)
|
371
400
|
when "extend"
|
372
401
|
args = node.arguments
|
373
402
|
|
@@ -415,6 +444,13 @@ module RBI
|
|
415
444
|
case last_node
|
416
445
|
when Method, Attr
|
417
446
|
last_node.visibility = parse_visibility(node.name.to_s, node)
|
447
|
+
when Send
|
448
|
+
current_scope << Send.new(
|
449
|
+
message,
|
450
|
+
parse_send_args(node.arguments),
|
451
|
+
loc: node_loc(node),
|
452
|
+
comments: node_comments(node),
|
453
|
+
)
|
418
454
|
else
|
419
455
|
raise ParseError.new(
|
420
456
|
"Unexpected token `#{node.message}` before `#{last_node&.string&.strip}`",
|
@@ -470,7 +506,7 @@ module RBI
|
|
470
506
|
|
471
507
|
last_node_last_line = node.child_nodes.last&.location&.end_line
|
472
508
|
|
473
|
-
|
509
|
+
first_line.upto(last_line) do |line|
|
474
510
|
comment = @comments_by_line[line]
|
475
511
|
next unless comment
|
476
512
|
break if last_node_last_line && line <= last_node_last_line
|
@@ -516,10 +552,15 @@ module RBI
|
|
516
552
|
sigs
|
517
553
|
end
|
518
554
|
|
519
|
-
sig { returns(T::Array[Comment]) }
|
520
|
-
def
|
521
|
-
comments =
|
522
|
-
|
555
|
+
sig { params(sigs: T::Array[Sig]).returns(T::Array[Comment]) }
|
556
|
+
def detach_comments_from_sigs(sigs)
|
557
|
+
comments = T.let([], T::Array[Comment])
|
558
|
+
|
559
|
+
sigs.each do |sig|
|
560
|
+
comments += sig.comments.dup
|
561
|
+
sig.comments.clear
|
562
|
+
end
|
563
|
+
|
523
564
|
comments
|
524
565
|
end
|
525
566
|
|
@@ -646,11 +687,10 @@ module RBI
|
|
646
687
|
|
647
688
|
sig { params(node: Prism::CallNode).returns(Sig) }
|
648
689
|
def parse_sig(node)
|
649
|
-
@last_sigs_comments = node_comments(node)
|
650
|
-
|
651
690
|
builder = SigBuilder.new(@source, file: @file)
|
652
691
|
builder.current.loc = node_loc(node)
|
653
692
|
builder.visit_call_node(node)
|
693
|
+
builder.current.comments = node_comments(node)
|
654
694
|
builder.current
|
655
695
|
end
|
656
696
|
|
@@ -719,7 +759,7 @@ module RBI
|
|
719
759
|
comments = node_comments(send)
|
720
760
|
default_value = T.let(nil, T.nilable(String))
|
721
761
|
|
722
|
-
rest
|
762
|
+
rest.each do |arg|
|
723
763
|
next unless arg.is_a?(Prism::KeywordHashNode)
|
724
764
|
|
725
765
|
arg.elements.each do |assoc|
|
@@ -745,11 +785,11 @@ module RBI
|
|
745
785
|
def parse_visibility(name, node)
|
746
786
|
case name
|
747
787
|
when "public"
|
748
|
-
Public.new(loc: node_loc(node))
|
788
|
+
Public.new(loc: node_loc(node), comments: node_comments(node))
|
749
789
|
when "protected"
|
750
|
-
Protected.new(loc: node_loc(node))
|
790
|
+
Protected.new(loc: node_loc(node), comments: node_comments(node))
|
751
791
|
when "private"
|
752
|
-
Private.new(loc: node_loc(node))
|
792
|
+
Private.new(loc: node_loc(node), comments: node_comments(node))
|
753
793
|
else
|
754
794
|
raise ParseError.new("Unexpected visibility `#{name}`", node_loc(node))
|
755
795
|
end
|
@@ -781,10 +821,7 @@ module RBI
|
|
781
821
|
|
782
822
|
sig { params(node: T.nilable(Prism::Node)).returns(T::Boolean) }
|
783
823
|
def type_variable_definition?(node)
|
784
|
-
|
785
|
-
return false unless node.block
|
786
|
-
|
787
|
-
node.message == "type_member" || node.message == "type_template"
|
824
|
+
node.is_a?(Prism::CallNode) && (node.message == "type_member" || node.message == "type_template")
|
788
825
|
end
|
789
826
|
end
|
790
827
|
|
@@ -839,7 +876,7 @@ module RBI
|
|
839
876
|
end
|
840
877
|
end
|
841
878
|
when "void"
|
842
|
-
@current.return_type =
|
879
|
+
@current.return_type = "void"
|
843
880
|
end
|
844
881
|
|
845
882
|
visit(node.receiver)
|