rbs 4.0.0.dev.4 → 4.0.0
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/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +18 -11
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +27 -34
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +323 -0
- data/README.md +1 -1
- data/Rakefile +43 -33
- data/Steepfile +1 -0
- data/config.yml +426 -24
- data/core/array.rbs +307 -227
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +179 -87
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +65 -2
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +280 -177
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -92
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1045 -739
- data/core/integer.rbs +135 -137
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +192 -144
- data/core/kernel.rbs +216 -155
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +15 -13
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +244 -106
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +74 -63
- data/core/object.rbs +9 -11
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +371 -515
- data/core/random.rbs +21 -3
- data/core/range.rbs +159 -57
- data/core/rational.rbs +60 -89
- data/core/rbs/unnamed/argf.rbs +60 -53
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +38 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +4 -71
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +16 -82
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +490 -360
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +27 -26
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +135 -67
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +576 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +544 -116
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +16 -2
- data/ext/rbs_extension/class_constants.h +8 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +33 -56
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +44 -35
- data/include/rbs/ast.h +448 -173
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +293 -3
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +532 -22
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -106
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +147 -25
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -18
- data/lib/rbs/inline_parser.rb +342 -6
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +19 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +4 -3
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +315 -4
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +108 -2
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/definition_builder.rbs +2 -0
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -14
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/parser.rbs +31 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +410 -153
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +8 -48
- data/src/parser.c +977 -516
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -14
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +158 -139
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +217 -136
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +475 -357
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +22 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1177 -85
- data/stdlib/strscan/0/string_scanner.rbs +27 -25
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +26 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +6 -6
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +50 -6
|
@@ -31,6 +31,52 @@ module RBS
|
|
|
31
31
|
type: type.map_type_name { yield _1 }
|
|
32
32
|
) #: self
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
def type_fingerprint
|
|
36
|
+
[
|
|
37
|
+
"annots/node_type_assertion",
|
|
38
|
+
type.to_s
|
|
39
|
+
]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class AliasAnnotation < Base
|
|
44
|
+
attr_reader :keyword_location, :type_name_location, :type_name
|
|
45
|
+
|
|
46
|
+
def initialize(location:, prefix_location:, keyword_location:, type_name:, type_name_location:)
|
|
47
|
+
super(location, prefix_location)
|
|
48
|
+
@keyword_location = keyword_location
|
|
49
|
+
@type_name = type_name
|
|
50
|
+
@type_name_location = type_name_location
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def map_type_name
|
|
54
|
+
self.class.new(
|
|
55
|
+
location:,
|
|
56
|
+
prefix_location:,
|
|
57
|
+
keyword_location:,
|
|
58
|
+
type_name: type_name ? yield(type_name) : nil,
|
|
59
|
+
type_name_location:
|
|
60
|
+
) #: self
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class ClassAliasAnnotation < AliasAnnotation
|
|
65
|
+
def type_fingerprint
|
|
66
|
+
[
|
|
67
|
+
"annots/class-alias",
|
|
68
|
+
type_name&.to_s
|
|
69
|
+
]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class ModuleAliasAnnotation < AliasAnnotation
|
|
74
|
+
def type_fingerprint
|
|
75
|
+
[
|
|
76
|
+
"annots/module-alias",
|
|
77
|
+
type_name&.to_s
|
|
78
|
+
]
|
|
79
|
+
end
|
|
34
80
|
end
|
|
35
81
|
|
|
36
82
|
class ColonMethodTypeAnnotation < Base
|
|
@@ -50,17 +96,26 @@ module RBS
|
|
|
50
96
|
method_type: method_type.map_type {|type| type.map_type_name { yield _1 }}
|
|
51
97
|
) #: self
|
|
52
98
|
end
|
|
99
|
+
|
|
100
|
+
def type_fingerprint
|
|
101
|
+
[
|
|
102
|
+
"annots/colon_method_type",
|
|
103
|
+
annotations.map(&:to_s),
|
|
104
|
+
method_type.to_s
|
|
105
|
+
]
|
|
106
|
+
end
|
|
53
107
|
end
|
|
54
108
|
|
|
55
109
|
class MethodTypesAnnotation < Base
|
|
56
110
|
Overload = AST::Members::MethodDefinition::Overload
|
|
57
111
|
|
|
58
|
-
attr_reader :overloads, :vertical_bar_locations
|
|
112
|
+
attr_reader :overloads, :vertical_bar_locations, :dot3_location
|
|
59
113
|
|
|
60
|
-
def initialize(location:, prefix_location:, overloads:, vertical_bar_locations:)
|
|
114
|
+
def initialize(location:, prefix_location:, overloads:, vertical_bar_locations:, dot3_location:)
|
|
61
115
|
super(location, prefix_location)
|
|
62
116
|
@overloads = overloads
|
|
63
117
|
@vertical_bar_locations = vertical_bar_locations
|
|
118
|
+
@dot3_location = dot3_location
|
|
64
119
|
end
|
|
65
120
|
|
|
66
121
|
def map_type_name(&block)
|
|
@@ -71,7 +126,15 @@ module RBS
|
|
|
71
126
|
)
|
|
72
127
|
end
|
|
73
128
|
|
|
74
|
-
self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:) #: self
|
|
129
|
+
self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:, dot3_location:) #: self
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def type_fingerprint
|
|
133
|
+
[
|
|
134
|
+
"annots/method_types",
|
|
135
|
+
overloads.map { |o| [o.annotations.map(&:to_s), o.method_type.to_s] },
|
|
136
|
+
overloading: dot3_location ? true : false
|
|
137
|
+
]
|
|
75
138
|
end
|
|
76
139
|
end
|
|
77
140
|
|
|
@@ -83,6 +146,10 @@ module RBS
|
|
|
83
146
|
@skip_location = skip_location
|
|
84
147
|
@comment_location = comment_location
|
|
85
148
|
end
|
|
149
|
+
|
|
150
|
+
def type_fingerprint
|
|
151
|
+
"annots/skip"
|
|
152
|
+
end
|
|
86
153
|
end
|
|
87
154
|
|
|
88
155
|
class ReturnTypeAnnotation < Base
|
|
@@ -112,6 +179,229 @@ module RBS
|
|
|
112
179
|
comment_location: comment_location
|
|
113
180
|
) #: self
|
|
114
181
|
end
|
|
182
|
+
|
|
183
|
+
def type_fingerprint
|
|
184
|
+
[
|
|
185
|
+
"annots/return_type",
|
|
186
|
+
return_type.to_s,
|
|
187
|
+
comment_location&.source
|
|
188
|
+
]
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
class TypeApplicationAnnotation < Base
|
|
193
|
+
attr_reader :type_args, :close_bracket_location, :comma_locations
|
|
194
|
+
|
|
195
|
+
def initialize(location:, prefix_location:, type_args:, close_bracket_location:, comma_locations:)
|
|
196
|
+
super(location, prefix_location)
|
|
197
|
+
@type_args = type_args
|
|
198
|
+
@close_bracket_location = close_bracket_location
|
|
199
|
+
@comma_locations = comma_locations
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def map_type_name(&block)
|
|
203
|
+
mapped_type_args = type_args.map { |type| type.map_type_name { yield _1 } }
|
|
204
|
+
|
|
205
|
+
self.class.new(
|
|
206
|
+
location:,
|
|
207
|
+
prefix_location:,
|
|
208
|
+
type_args: mapped_type_args,
|
|
209
|
+
close_bracket_location:,
|
|
210
|
+
comma_locations:
|
|
211
|
+
) #: self
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def type_fingerprint
|
|
215
|
+
[
|
|
216
|
+
"annots/type_application",
|
|
217
|
+
type_args.map(&:to_s)
|
|
218
|
+
]
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
class InstanceVariableAnnotation < Base
|
|
223
|
+
attr_reader :ivar_name, :ivar_name_location, :colon_location, :type, :comment_location
|
|
224
|
+
|
|
225
|
+
def initialize(location:, prefix_location:, ivar_name:, ivar_name_location:, colon_location:, type:, comment_location:)
|
|
226
|
+
super(location, prefix_location)
|
|
227
|
+
@ivar_name = ivar_name
|
|
228
|
+
@ivar_name_location = ivar_name_location
|
|
229
|
+
@colon_location = colon_location
|
|
230
|
+
@type = type
|
|
231
|
+
@comment_location = comment_location
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def map_type_name(&block)
|
|
235
|
+
self.class.new(
|
|
236
|
+
location:,
|
|
237
|
+
prefix_location:,
|
|
238
|
+
ivar_name:,
|
|
239
|
+
ivar_name_location:,
|
|
240
|
+
colon_location:,
|
|
241
|
+
type: type.map_type_name { yield _1 },
|
|
242
|
+
comment_location:
|
|
243
|
+
) #: self
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def type_fingerprint
|
|
247
|
+
[
|
|
248
|
+
"annots/instance_variable",
|
|
249
|
+
ivar_name.to_s,
|
|
250
|
+
type.to_s,
|
|
251
|
+
comment_location&.source
|
|
252
|
+
]
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
class ParamTypeAnnotation < Base
|
|
257
|
+
attr_reader :name_location, :colon_location, :param_type, :comment_location
|
|
258
|
+
|
|
259
|
+
def initialize(location:, prefix_location:, name_location:, colon_location:, param_type:, comment_location:)
|
|
260
|
+
super(location, prefix_location)
|
|
261
|
+
@name_location = name_location
|
|
262
|
+
@colon_location = colon_location
|
|
263
|
+
@param_type = param_type
|
|
264
|
+
@comment_location = comment_location
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def map_type_name(&block)
|
|
268
|
+
self.class.new(
|
|
269
|
+
location:,
|
|
270
|
+
prefix_location:,
|
|
271
|
+
name_location: name_location,
|
|
272
|
+
colon_location: colon_location,
|
|
273
|
+
param_type: param_type.map_type_name { yield _1 },
|
|
274
|
+
comment_location: comment_location
|
|
275
|
+
) #: self
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def type_fingerprint
|
|
279
|
+
[
|
|
280
|
+
"annots/param_type",
|
|
281
|
+
name_location.source,
|
|
282
|
+
param_type.to_s,
|
|
283
|
+
comment_location&.source
|
|
284
|
+
]
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
class SplatParamTypeAnnotation < Base
|
|
289
|
+
attr_reader :star_location, :name_location, :colon_location, :param_type, :comment_location
|
|
290
|
+
|
|
291
|
+
def initialize(location:, prefix_location:, star_location:, name_location:, colon_location:, param_type:, comment_location:)
|
|
292
|
+
super(location, prefix_location)
|
|
293
|
+
@star_location = star_location
|
|
294
|
+
@name_location = name_location
|
|
295
|
+
@colon_location = colon_location
|
|
296
|
+
@param_type = param_type
|
|
297
|
+
@comment_location = comment_location
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def map_type_name(&block)
|
|
301
|
+
self.class.new(
|
|
302
|
+
location:,
|
|
303
|
+
prefix_location:,
|
|
304
|
+
star_location: star_location,
|
|
305
|
+
name_location: name_location,
|
|
306
|
+
colon_location: colon_location,
|
|
307
|
+
param_type: param_type.map_type_name { yield _1 },
|
|
308
|
+
comment_location: comment_location
|
|
309
|
+
) #: self
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def type_fingerprint
|
|
313
|
+
[
|
|
314
|
+
"annots/splat_param_type",
|
|
315
|
+
name_location&.source,
|
|
316
|
+
param_type.to_s,
|
|
317
|
+
comment_location&.source
|
|
318
|
+
]
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
class DoubleSplatParamTypeAnnotation < Base
|
|
323
|
+
attr_reader :star2_location, :name_location, :colon_location, :param_type, :comment_location
|
|
324
|
+
|
|
325
|
+
def initialize(location:, prefix_location:, star2_location:, name_location:, colon_location:, param_type:, comment_location:)
|
|
326
|
+
super(location, prefix_location)
|
|
327
|
+
@star2_location = star2_location
|
|
328
|
+
@name_location = name_location
|
|
329
|
+
@colon_location = colon_location
|
|
330
|
+
@param_type = param_type
|
|
331
|
+
@comment_location = comment_location
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def map_type_name(&block)
|
|
335
|
+
self.class.new(
|
|
336
|
+
location:,
|
|
337
|
+
prefix_location:,
|
|
338
|
+
star2_location: star2_location,
|
|
339
|
+
name_location: name_location,
|
|
340
|
+
colon_location: colon_location,
|
|
341
|
+
param_type: param_type.map_type_name { yield _1 },
|
|
342
|
+
comment_location: comment_location
|
|
343
|
+
) #: self
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def type_fingerprint
|
|
347
|
+
[
|
|
348
|
+
"annots/double_splat_param_type",
|
|
349
|
+
name_location&.source,
|
|
350
|
+
param_type.to_s,
|
|
351
|
+
comment_location&.source
|
|
352
|
+
]
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
class BlockParamTypeAnnotation < Base
|
|
357
|
+
attr_reader :ampersand_location, :name_location, :colon_location, :question_location, :type_location, :type, :comment_location
|
|
358
|
+
|
|
359
|
+
def initialize(location:, prefix_location:, ampersand_location:, name_location:, colon_location:, question_location:, type_location:, type:, comment_location:)
|
|
360
|
+
super(location, prefix_location)
|
|
361
|
+
@ampersand_location = ampersand_location
|
|
362
|
+
@name_location = name_location
|
|
363
|
+
@colon_location = colon_location
|
|
364
|
+
@question_location = question_location
|
|
365
|
+
@type_location = type_location
|
|
366
|
+
@type = type
|
|
367
|
+
@comment_location = comment_location
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def map_type_name(&block)
|
|
371
|
+
self.class.new(
|
|
372
|
+
location:,
|
|
373
|
+
prefix_location:,
|
|
374
|
+
ampersand_location: ampersand_location,
|
|
375
|
+
name_location: name_location,
|
|
376
|
+
colon_location: colon_location,
|
|
377
|
+
question_location: question_location,
|
|
378
|
+
type_location: type_location,
|
|
379
|
+
type: type.map_type_name { yield _1 },
|
|
380
|
+
comment_location: comment_location
|
|
381
|
+
) #: self
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def name
|
|
385
|
+
name_location&.source&.to_sym
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def optional?
|
|
389
|
+
question_location ? true : false
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def required?
|
|
393
|
+
!optional?
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def type_fingerprint
|
|
397
|
+
[
|
|
398
|
+
"annots/block_param_type",
|
|
399
|
+
name_location&.source,
|
|
400
|
+
type.to_s,
|
|
401
|
+
optional? ? "optional" : "required",
|
|
402
|
+
comment_location&.source
|
|
403
|
+
]
|
|
404
|
+
end
|
|
115
405
|
end
|
|
116
406
|
end
|
|
117
407
|
end
|
|
@@ -177,6 +177,13 @@ module RBS
|
|
|
177
177
|
Location.new(comment_buffer, start_offset, end_offset)
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
+
def location()
|
|
181
|
+
first_comment = comments[0] or raise
|
|
182
|
+
last_comment = comments[-1] or raise
|
|
183
|
+
|
|
184
|
+
comment_buffer.rbs_location(first_comment.location.join last_comment.location)
|
|
185
|
+
end
|
|
186
|
+
|
|
180
187
|
def parse_annotation_lines(start_line, end_line, variables)
|
|
181
188
|
start_pos = comment_buffer.ranges[start_line].begin
|
|
182
189
|
end_pos = comment_buffer.ranges[end_line].end
|
|
@@ -215,6 +222,23 @@ module RBS
|
|
|
215
222
|
|
|
216
223
|
false
|
|
217
224
|
end
|
|
225
|
+
|
|
226
|
+
def as_comment
|
|
227
|
+
lines = [] #: Array[String]
|
|
228
|
+
|
|
229
|
+
each_paragraph([]) do |paragraph|
|
|
230
|
+
case paragraph
|
|
231
|
+
when Location
|
|
232
|
+
lines << paragraph.local_source
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
string = lines.join("\n")
|
|
237
|
+
|
|
238
|
+
unless string.strip.empty?
|
|
239
|
+
AST::Comment.new(string: string, location: location)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
218
242
|
end
|
|
219
243
|
end
|
|
220
244
|
end
|
|
@@ -16,17 +16,67 @@ module RBS
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
class ClassDecl < Base
|
|
19
|
+
class SuperClass
|
|
20
|
+
attr_reader :type_name_location
|
|
21
|
+
|
|
22
|
+
attr_reader :operator_location
|
|
23
|
+
|
|
24
|
+
attr_reader :type_name
|
|
25
|
+
|
|
26
|
+
attr_reader :type_annotation
|
|
27
|
+
|
|
28
|
+
def initialize(type_name_location, operator_location, type_name, type_annotation)
|
|
29
|
+
@type_name_location = type_name_location
|
|
30
|
+
@operator_location = operator_location
|
|
31
|
+
@type_name = type_name
|
|
32
|
+
@type_annotation = type_annotation
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def type_args
|
|
36
|
+
if type_annotation
|
|
37
|
+
type_annotation.type_args
|
|
38
|
+
else
|
|
39
|
+
[]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def location
|
|
44
|
+
if type_annotation
|
|
45
|
+
Location.new(
|
|
46
|
+
type_name_location.buffer,
|
|
47
|
+
type_name_location.start_pos,
|
|
48
|
+
type_annotation.location.end_pos
|
|
49
|
+
)
|
|
50
|
+
else
|
|
51
|
+
type_name_location
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
alias name type_name
|
|
56
|
+
alias args type_args
|
|
57
|
+
|
|
58
|
+
def type_fingerprint
|
|
59
|
+
[
|
|
60
|
+
type_name.to_s,
|
|
61
|
+
type_annotation&.type_fingerprint
|
|
62
|
+
]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
19
66
|
attr_reader :class_name
|
|
20
67
|
|
|
21
68
|
attr_reader :members
|
|
22
69
|
|
|
23
70
|
attr_reader :node
|
|
24
71
|
|
|
25
|
-
|
|
72
|
+
attr_reader :super_class
|
|
73
|
+
|
|
74
|
+
def initialize(buffer, name, node, super_class)
|
|
26
75
|
super(buffer)
|
|
27
76
|
@class_name = name
|
|
28
77
|
@node = node
|
|
29
78
|
@members = []
|
|
79
|
+
@super_class = super_class
|
|
30
80
|
end
|
|
31
81
|
|
|
32
82
|
def each_decl(&block)
|
|
@@ -39,13 +89,26 @@ module RBS
|
|
|
39
89
|
end
|
|
40
90
|
end
|
|
41
91
|
|
|
42
|
-
def super_class = nil
|
|
43
|
-
|
|
44
92
|
def type_params = []
|
|
45
93
|
|
|
46
94
|
def location
|
|
47
95
|
rbs_location(node.location)
|
|
48
96
|
end
|
|
97
|
+
|
|
98
|
+
def name_location
|
|
99
|
+
rbs_location(node.constant_path.location)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def type_fingerprint
|
|
103
|
+
result = [] #: Array[untyped]
|
|
104
|
+
|
|
105
|
+
result << "decls/class"
|
|
106
|
+
result << class_name.to_s
|
|
107
|
+
result << super_class&.type_fingerprint
|
|
108
|
+
result << members.map { _1.type_fingerprint }
|
|
109
|
+
|
|
110
|
+
result
|
|
111
|
+
end
|
|
49
112
|
end
|
|
50
113
|
|
|
51
114
|
class ModuleDecl < Base
|
|
@@ -79,6 +142,138 @@ module RBS
|
|
|
79
142
|
def location
|
|
80
143
|
rbs_location(node.location)
|
|
81
144
|
end
|
|
145
|
+
|
|
146
|
+
def name_location
|
|
147
|
+
rbs_location(node.constant_path.location)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def type_fingerprint
|
|
151
|
+
result = [] #: Array[untyped]
|
|
152
|
+
|
|
153
|
+
result << "decls/module"
|
|
154
|
+
result << module_name.to_s
|
|
155
|
+
result << members.map { _1.type_fingerprint}
|
|
156
|
+
|
|
157
|
+
result
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
class ConstantDecl < Base
|
|
162
|
+
attr_reader :leading_comment
|
|
163
|
+
attr_reader :constant_name
|
|
164
|
+
attr_reader :node
|
|
165
|
+
attr_reader :type_annotation
|
|
166
|
+
|
|
167
|
+
def initialize(buffer, constant_name, node, leading_comment, type_annotation)
|
|
168
|
+
super(buffer)
|
|
169
|
+
@constant_name = constant_name
|
|
170
|
+
@node = node
|
|
171
|
+
@leading_comment = leading_comment
|
|
172
|
+
@type_annotation = type_annotation
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def location
|
|
176
|
+
rbs_location(node.location)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def name_location
|
|
180
|
+
case node
|
|
181
|
+
when Prism::ConstantWriteNode
|
|
182
|
+
rbs_location(node.name_loc)
|
|
183
|
+
when Prism::ConstantPathWriteNode
|
|
184
|
+
rbs_location(node.target.location)
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def type
|
|
189
|
+
return type_annotation.type if type_annotation
|
|
190
|
+
|
|
191
|
+
case node.value
|
|
192
|
+
when Prism::IntegerNode
|
|
193
|
+
BuiltinNames::Integer.instance_type
|
|
194
|
+
when Prism::FloatNode
|
|
195
|
+
BuiltinNames::Float.instance_type
|
|
196
|
+
when Prism::StringNode
|
|
197
|
+
BuiltinNames::String.instance_type
|
|
198
|
+
when Prism::TrueNode, Prism::FalseNode
|
|
199
|
+
Types::Bases::Bool.new(location: nil)
|
|
200
|
+
when Prism::SymbolNode
|
|
201
|
+
BuiltinNames::Symbol.instance_type
|
|
202
|
+
when Prism::NilNode
|
|
203
|
+
Types::Bases::Nil.new(location: nil)
|
|
204
|
+
else
|
|
205
|
+
Types::Bases::Any.new(location: nil)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def comment
|
|
210
|
+
leading_comment&.as_comment
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def type_fingerprint
|
|
214
|
+
[
|
|
215
|
+
"decls/constant",
|
|
216
|
+
constant_name.to_s,
|
|
217
|
+
type.to_s,
|
|
218
|
+
leading_comment&.as_comment&.string
|
|
219
|
+
]
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
class ClassModuleAliasDecl < Base
|
|
224
|
+
attr_reader :node
|
|
225
|
+
attr_reader :leading_comment
|
|
226
|
+
attr_reader :new_name
|
|
227
|
+
attr_reader :infered_old_name
|
|
228
|
+
attr_reader :annotation
|
|
229
|
+
|
|
230
|
+
def initialize(buffer, node, new_name, infered_old_name, leading_comment, annotation)
|
|
231
|
+
super(buffer)
|
|
232
|
+
@node = node
|
|
233
|
+
@new_name = new_name
|
|
234
|
+
@infered_old_name = infered_old_name
|
|
235
|
+
@leading_comment = leading_comment
|
|
236
|
+
@annotation = annotation
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def location
|
|
240
|
+
rbs_location(node.location)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def name_location
|
|
244
|
+
case node
|
|
245
|
+
when Prism::ConstantWriteNode
|
|
246
|
+
rbs_location(node.name_loc)
|
|
247
|
+
when Prism::ConstantPathWriteNode
|
|
248
|
+
rbs_location(node.target.location)
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def old_name
|
|
253
|
+
# Return explicit type name from annotation if provided, otherwise use inferred name
|
|
254
|
+
case
|
|
255
|
+
when annotation.type_name
|
|
256
|
+
annotation.type_name
|
|
257
|
+
when infered_old_name
|
|
258
|
+
infered_old_name
|
|
259
|
+
else
|
|
260
|
+
raise "No old name available"
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def comment
|
|
265
|
+
leading_comment&.as_comment
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def type_fingerprint
|
|
269
|
+
[
|
|
270
|
+
"decls/class_module_alias",
|
|
271
|
+
annotation.type_fingerprint,
|
|
272
|
+
new_name.to_s,
|
|
273
|
+
old_name.to_s,
|
|
274
|
+
leading_comment&.as_comment&.string
|
|
275
|
+
]
|
|
276
|
+
end
|
|
82
277
|
end
|
|
83
278
|
end
|
|
84
279
|
end
|
|
@@ -15,6 +15,10 @@ module RBS
|
|
|
15
15
|
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
|
|
16
16
|
nil
|
|
17
17
|
end
|
|
18
|
+
when Prism::ConstantWriteNode
|
|
19
|
+
TypeName.new(name: node.name, namespace: Namespace.empty)
|
|
20
|
+
when Prism::ConstantPathWriteNode
|
|
21
|
+
constant_as_type_name(node.target)
|
|
18
22
|
end
|
|
19
23
|
end
|
|
20
24
|
end
|