rbs 2.0.0 → 2.2.2

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.
Files changed (208) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +34 -0
  3. data/.github/workflows/ruby.yml +5 -0
  4. data/CHANGELOG.md +82 -0
  5. data/README.md +6 -1
  6. data/Rakefile +56 -21
  7. data/core/array.rbs +2866 -1086
  8. data/core/basic_object.rbs +150 -30
  9. data/core/binding.rbs +33 -0
  10. data/core/builtin.rbs +4 -4
  11. data/core/class.rbs +43 -5
  12. data/core/comparable.rbs +57 -0
  13. data/core/complex.rbs +170 -4
  14. data/core/constants.rbs +51 -0
  15. data/core/deprecated.rbs +7 -0
  16. data/core/dir.rbs +305 -20
  17. data/core/encoding.rbs +1214 -77
  18. data/core/enumerable.rbs +2173 -234
  19. data/core/enumerator.rbs +448 -182
  20. data/core/env.rbs +448 -1
  21. data/core/errno.rbs +1 -10
  22. data/core/errors.rbs +152 -2
  23. data/core/exception.rbs +201 -127
  24. data/core/false_class.rbs +27 -0
  25. data/core/fiber.rbs +118 -37
  26. data/core/fiber_error.rbs +8 -9
  27. data/core/file.rbs +1060 -142
  28. data/core/file_test.rbs +287 -32
  29. data/core/float.rbs +776 -300
  30. data/core/gc.rbs +185 -34
  31. data/core/global_variables.rbs +5 -1
  32. data/core/hash.rbs +1582 -649
  33. data/core/integer.rbs +974 -204
  34. data/core/io/buffer.rbs +710 -0
  35. data/core/io/wait.rbs +29 -8
  36. data/core/io.rbs +2438 -417
  37. data/core/kernel.rbs +2319 -318
  38. data/core/marshal.rbs +37 -2
  39. data/core/match_data.rbs +123 -6
  40. data/core/math.rbs +126 -6
  41. data/core/method.rbs +226 -102
  42. data/core/module.rbs +421 -45
  43. data/core/nil_class.rbs +64 -0
  44. data/core/numeric.rbs +620 -142
  45. data/core/object.rbs +453 -81
  46. data/core/object_space.rbs +92 -2
  47. data/core/proc.rbs +482 -285
  48. data/core/process.rbs +443 -34
  49. data/core/ractor.rbs +232 -9
  50. data/core/random.rbs +151 -52
  51. data/core/range.rbs +885 -160
  52. data/core/rational.rbs +122 -6
  53. data/core/rb_config.rbs +14 -4
  54. data/core/refinement.rbs +44 -0
  55. data/core/regexp.rbs +156 -14
  56. data/core/ruby_vm.rbs +42 -3
  57. data/core/signal.rbs +78 -39
  58. data/core/string.rbs +2123 -567
  59. data/core/string_io.rbs +204 -0
  60. data/core/struct.rbs +283 -28
  61. data/core/symbol.rbs +304 -30
  62. data/core/thread.rbs +1288 -688
  63. data/core/thread_group.rbs +66 -10
  64. data/core/time.rbs +643 -217
  65. data/core/trace_point.rbs +100 -12
  66. data/core/true_class.rbs +24 -0
  67. data/core/unbound_method.rbs +73 -7
  68. data/core/warning.rbs +37 -12
  69. data/docs/CONTRIBUTING.md +40 -34
  70. data/docs/stdlib.md +3 -102
  71. data/docs/syntax.md +54 -11
  72. data/ext/rbs_extension/extconf.rb +1 -0
  73. data/ext/rbs_extension/lexer.h +5 -0
  74. data/ext/rbs_extension/lexstate.c +6 -0
  75. data/ext/rbs_extension/parser.c +85 -10
  76. data/ext/rbs_extension/ruby_objs.c +4 -2
  77. data/ext/rbs_extension/ruby_objs.h +2 -2
  78. data/goodcheck.yml +0 -11
  79. data/lib/rbs/annotate/annotations.rb +197 -0
  80. data/lib/rbs/annotate/formatter.rb +80 -0
  81. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  82. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  83. data/lib/rbs/annotate.rb +6 -0
  84. data/lib/rbs/ast/members.rb +21 -13
  85. data/lib/rbs/buffer.rb +17 -11
  86. data/lib/rbs/cli.rb +48 -1
  87. data/lib/rbs/definition_builder/method_builder.rb +28 -16
  88. data/lib/rbs/definition_builder.rb +6 -2
  89. data/lib/rbs/environment.rb +8 -4
  90. data/lib/rbs/location_aux.rb +12 -0
  91. data/lib/rbs/namespace.rb +1 -1
  92. data/lib/rbs/prototype/rb.rb +12 -0
  93. data/lib/rbs/type_alias_regularity.rb +6 -4
  94. data/lib/rbs/type_name.rb +1 -1
  95. data/lib/rbs/types.rb +1 -1
  96. data/lib/rbs/validator.rb +6 -0
  97. data/lib/rbs/version.rb +1 -1
  98. data/lib/rbs/writer.rb +54 -4
  99. data/lib/rbs.rb +0 -2
  100. data/schema/typeParam.json +3 -3
  101. data/sig/annotate/annotations.rbs +102 -0
  102. data/sig/annotate/formatter.rbs +24 -0
  103. data/sig/annotate/rdoc_annotater.rbs +82 -0
  104. data/sig/annotate/rdoc_source.rbs +30 -0
  105. data/sig/buffer.rbs +6 -2
  106. data/sig/cli.rbs +2 -0
  107. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  108. data/sig/location.rbs +6 -0
  109. data/sig/members.rbs +24 -18
  110. data/sig/method_builder.rbs +5 -4
  111. data/sig/method_types.rbs +5 -1
  112. data/sig/polyfill.rbs +78 -0
  113. data/sig/validator.rbs +3 -1
  114. data/sig/writer.rbs +79 -2
  115. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  116. data/stdlib/abbrev/0/array.rbs +26 -0
  117. data/stdlib/base64/0/base64.rbs +31 -0
  118. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  119. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  120. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  121. data/stdlib/cgi/0/core.rbs +649 -21
  122. data/stdlib/coverage/0/coverage.rbs +164 -2
  123. data/stdlib/csv/0/csv.rbs +2862 -398
  124. data/stdlib/date/0/date.rbs +483 -25
  125. data/stdlib/date/0/date_time.rbs +187 -12
  126. data/stdlib/dbm/0/dbm.rbs +152 -17
  127. data/stdlib/digest/0/digest.rbs +146 -0
  128. data/stdlib/erb/0/erb.rbs +65 -245
  129. data/stdlib/fiber/0/fiber.rbs +73 -91
  130. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  131. data/stdlib/find/0/find.rbs +9 -0
  132. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  133. data/stdlib/io-console/0/io-console.rbs +227 -15
  134. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  135. data/stdlib/json/0/json.rbs +1147 -145
  136. data/stdlib/logger/0/formatter.rbs +24 -0
  137. data/stdlib/logger/0/log_device.rbs +64 -0
  138. data/stdlib/logger/0/logger.rbs +165 -13
  139. data/stdlib/logger/0/period.rbs +10 -0
  140. data/stdlib/logger/0/severity.rbs +26 -0
  141. data/stdlib/monitor/0/monitor.rbs +163 -0
  142. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  143. data/stdlib/net-http/0/manifest.yaml +1 -0
  144. data/stdlib/net-http/0/net-http.rbs +1513 -683
  145. data/stdlib/nkf/0/nkf.rbs +372 -0
  146. data/stdlib/objspace/0/objspace.rbs +149 -90
  147. data/stdlib/openssl/0/openssl.rbs +8108 -71
  148. data/stdlib/optparse/0/optparse.rbs +487 -19
  149. data/stdlib/pathname/0/pathname.rbs +425 -124
  150. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  151. data/stdlib/prime/0/integer-extension.rbs +20 -2
  152. data/stdlib/prime/0/prime.rbs +88 -21
  153. data/stdlib/pstore/0/pstore.rbs +102 -0
  154. data/stdlib/pty/0/pty.rbs +64 -14
  155. data/stdlib/resolv/0/resolv.rbs +420 -31
  156. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  157. data/stdlib/rubygems/0/config_file.rbs +33 -1
  158. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  159. data/stdlib/rubygems/0/installer.rbs +13 -1
  160. data/stdlib/rubygems/0/path_support.rbs +4 -1
  161. data/stdlib/rubygems/0/platform.rbs +5 -1
  162. data/stdlib/rubygems/0/request_set.rbs +44 -2
  163. data/stdlib/rubygems/0/requirement.rbs +65 -2
  164. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  165. data/stdlib/rubygems/0/source_list.rbs +13 -0
  166. data/stdlib/rubygems/0/specification.rbs +21 -1
  167. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  168. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  169. data/stdlib/rubygems/0/version.rbs +60 -157
  170. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  171. data/stdlib/set/0/set.rbs +423 -109
  172. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  173. data/stdlib/singleton/0/singleton.rbs +20 -0
  174. data/stdlib/socket/0/addrinfo.rbs +210 -9
  175. data/stdlib/socket/0/basic_socket.rbs +103 -11
  176. data/stdlib/socket/0/ip_socket.rbs +31 -9
  177. data/stdlib/socket/0/socket.rbs +586 -38
  178. data/stdlib/socket/0/tcp_server.rbs +22 -2
  179. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  180. data/stdlib/socket/0/udp_socket.rbs +25 -2
  181. data/stdlib/socket/0/unix_server.rbs +22 -2
  182. data/stdlib/socket/0/unix_socket.rbs +45 -5
  183. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  184. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  185. data/stdlib/time/0/time.rbs +208 -116
  186. data/stdlib/timeout/0/timeout.rbs +10 -0
  187. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  188. data/stdlib/tsort/0/cyclic.rbs +1 -0
  189. data/stdlib/tsort/0/interfaces.rbs +1 -0
  190. data/stdlib/tsort/0/tsort.rbs +42 -0
  191. data/stdlib/uri/0/common.rbs +57 -8
  192. data/stdlib/uri/0/file.rbs +55 -109
  193. data/stdlib/uri/0/ftp.rbs +6 -3
  194. data/stdlib/uri/0/generic.rbs +558 -329
  195. data/stdlib/uri/0/http.rbs +60 -114
  196. data/stdlib/uri/0/https.rbs +8 -102
  197. data/stdlib/uri/0/ldap.rbs +143 -137
  198. data/stdlib/uri/0/ldaps.rbs +8 -102
  199. data/stdlib/uri/0/mailto.rbs +3 -0
  200. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  201. data/stdlib/uri/0/ws.rbs +6 -3
  202. data/stdlib/uri/0/wss.rbs +5 -3
  203. data/stdlib/yaml/0/dbm.rbs +151 -87
  204. data/stdlib/yaml/0/store.rbs +6 -0
  205. data/stdlib/zlib/0/zlib.rbs +90 -31
  206. metadata +18 -6
  207. data/lib/rbs/location.rb +0 -221
  208. data/sig/char_scanner.rbs +0 -9
data/lib/rbs/writer.rb CHANGED
@@ -6,6 +6,16 @@ module RBS
6
6
  def initialize(out:)
7
7
  @out = out
8
8
  @indentation = []
9
+ @preserve = false
10
+ end
11
+
12
+ def preserve?
13
+ @preserve
14
+ end
15
+
16
+ def preserve!(preserve: true)
17
+ @preserve = preserve
18
+ self
9
19
  end
10
20
 
11
21
  def indent(size = 2)
@@ -119,7 +129,9 @@ module RBS
119
129
  when AST::Declarations::Alias
120
130
  write_comment decl.comment
121
131
  write_annotation decl.annotations
122
- puts "type #{name_and_params(decl.name, decl.type_params)} = #{decl.type}"
132
+ write_loc_source(decl) {
133
+ puts "type #{name_and_params(decl.name, decl.type_params)} = #{decl.type}"
134
+ }
123
135
 
124
136
  when AST::Declarations::Interface
125
137
  write_comment decl.comment
@@ -163,6 +175,16 @@ module RBS
163
175
  end
164
176
  end
165
177
 
178
+ def put_lines(lines, leading_spaces:)
179
+ lines.each_line.with_index do |line, index|
180
+ line.chomp!
181
+ line.rstrip!
182
+ line.sub!(/\A( {,#{leading_spaces}})/, '') if index > 0
183
+
184
+ puts line
185
+ end
186
+ end
187
+
166
188
  def write_member(member)
167
189
  case member
168
190
  when AST::Members::Include
@@ -211,7 +233,7 @@ module RBS
211
233
  when AST::Members::MethodDefinition
212
234
  write_comment member.comment
213
235
  write_annotation member.annotations
214
- write_def member
236
+ write_loc_source(member) { write_def member }
215
237
  else
216
238
  write_decl member
217
239
  end
@@ -230,7 +252,25 @@ module RBS
230
252
  end
231
253
  end
232
254
 
255
+ def write_loc_source(located)
256
+ if preserve? && loc = located.location
257
+ put_lines(loc.source, leading_spaces: loc.start_column)
258
+ else
259
+ yield
260
+ end
261
+ end
262
+
233
263
  def write_def(member)
264
+ visibility =
265
+ case member.visibility
266
+ when :public
267
+ "public "
268
+ when :private
269
+ "private "
270
+ else
271
+ ""
272
+ end
273
+
234
274
  name = case member.kind
235
275
  when :instance
236
276
  "#{method_name(member.name)}"
@@ -242,7 +282,7 @@ module RBS
242
282
 
243
283
  string = ""
244
284
 
245
- prefix = "def #{name}:"
285
+ prefix = "#{visibility}def #{name}:"
246
286
  padding = " " * (prefix.size-1)
247
287
 
248
288
  string << prefix
@@ -270,6 +310,16 @@ module RBS
270
310
  end
271
311
 
272
312
  def attribute(kind, attr)
313
+ visibility =
314
+ case attr.visibility
315
+ when :public
316
+ "public "
317
+ when :private
318
+ "private "
319
+ else
320
+ ""
321
+ end
322
+
273
323
  var = case attr.ivar_name
274
324
  when nil
275
325
  ""
@@ -286,7 +336,7 @@ module RBS
286
336
  ""
287
337
  end
288
338
 
289
- "attr_#{kind} #{receiver}#{attr.name}#{var}: #{attr.type}"
339
+ "#{visibility}attr_#{kind} #{receiver}#{attr.name}#{var}: #{attr.type}"
290
340
  end
291
341
 
292
342
  def preserve_empty_line(prev, decl)
data/lib/rbs.rb CHANGED
@@ -7,9 +7,7 @@ require "pp"
7
7
  require "ripper"
8
8
  require "logger"
9
9
  require "tsort"
10
- require "strscan"
11
10
 
12
- require "rbs/char_scanner"
13
11
  require "rbs/errors"
14
12
  require "rbs/buffer"
15
13
  require "rbs/namespace"
@@ -15,13 +15,13 @@
15
15
  "upper_bound": {
16
16
  "oneOf": [
17
17
  {
18
- "$ref": "types.json#definitions/classInstance"
18
+ "$ref": "types.json#/definitions/classInstance"
19
19
  },
20
20
  {
21
- "$ref": "types.json#definitions/classSingleton"
21
+ "$ref": "types.json#/definitions/classSingleton"
22
22
  },
23
23
  {
24
- "$ref": "types.json#definitions/interface"
24
+ "$ref": "types.json#/definitions/interface"
25
25
  },
26
26
  {
27
27
  "type": "null"
@@ -0,0 +1,102 @@
1
+ module RBS
2
+ module Annotate
3
+ class Annotations
4
+ type t = Skip | Source | Copy
5
+
6
+ def self.parse: (AST::Annotation) -> t?
7
+
8
+ attr_reader items: Array[t]
9
+
10
+ def initialize: (Array[t]) -> void
11
+
12
+ def skip?: () -> bool
13
+
14
+ def skip_all?: () -> bool
15
+
16
+ def test_path: (String path) -> bool
17
+
18
+ def test_path_string: (String pattern, String path) -> bool
19
+
20
+ def copy_annotation: -> Copy?
21
+
22
+ # Skip annotation allows skipping generating annotation of a subject.
23
+ #
24
+ # %a{annotate:rdoc:skip}
25
+ # %a{annotate:rdoc:skip:all}
26
+ #
27
+ class Skip
28
+ attr_reader annotation: AST::Annotation
29
+
30
+ attr_reader skip_children: bool
31
+
32
+ def initialize: (annotation: AST::Annotation, skip_children: bool) -> void
33
+
34
+ def hash: () -> Integer
35
+
36
+ def ==: (untyped) -> bool
37
+
38
+ alias eql? ==
39
+ end
40
+
41
+ # Source annotation allows where the documents are copied from.
42
+ #
43
+ # It allows specifying two directions: the source to read from, and the source to skip.
44
+ #
45
+ # %a{annotate:rdoc:source:from=ext/pathname}
46
+ # %a{annotate:rdoc:source:skip=ext/pathname/doc}
47
+ #
48
+ # When you want to specify several paths, repeat writing the Source annotation.
49
+ #
50
+ class Source
51
+ attr_reader annotation: AST::Annotation
52
+
53
+ attr_reader include_source: String?
54
+ attr_reader skip_source: String?
55
+
56
+ def initialize: (annotation: AST::Annotation, include: String) -> void
57
+ | (annotation: AST::Annotation, skip: String) -> void
58
+
59
+ def hash: () -> Integer
60
+
61
+ def ==: (untyped) -> bool
62
+
63
+ alias eql? ==
64
+ end
65
+
66
+ # Copy annotation allows copying the doc from another subject.
67
+ # This helps working with incorrect RDoc annotations.
68
+ #
69
+ # %a{annotate:rdoc:copy:Bar#baz}
70
+ # %a{annotate:rdoc:copy:Bar.baz}
71
+ # %a{annotate:rdoc:copy:Bar::Baz}
72
+ #
73
+ class Copy
74
+ attr_reader annotation: AST::Annotation
75
+
76
+ attr_reader source: String
77
+
78
+ def initialize: (annotation: AST::Annotation, source: String) -> void
79
+
80
+ # Returns a tuple of:
81
+ #
82
+ # - Type name
83
+ # - A pair of:
84
+ # - Boolean which holds if it is singleton
85
+ # - Name of method
86
+ def partition: () -> [TypeName, [bool, Symbol]?]
87
+
88
+ def type_name: () -> TypeName
89
+
90
+ def method_name: () -> Symbol?
91
+
92
+ def singleton?: () -> bool
93
+
94
+ def hash: () -> Integer
95
+
96
+ def ==: (untyped) -> bool
97
+
98
+ alias eql? ==
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,24 @@
1
+ module RBS
2
+ module Annotate
3
+ class Formatter
4
+ attr_reader buffer: String
5
+
6
+ @pending_separator: String?
7
+
8
+ def initialize: () -> void
9
+
10
+ def <<: (String | RDoc::Markup::Document | nil) -> self
11
+
12
+ def margin: (?separator: String) -> self
13
+
14
+ def empty?: () -> bool
15
+
16
+ def format: (newline_at_end: bool) -> String
17
+
18
+ def self.translate: (RDoc::Markup::Document) -> String?
19
+
20
+ def self.each_part: (RDoc::Markup::Document) { (RDoc::Markup::Document) -> void } -> void
21
+ | (RDoc::Markup::Document) -> Enumerator[RDoc::Markup::Document, void]
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,82 @@
1
+ module RBS
2
+ module Annotate
3
+ class RDocAnnotator
4
+ attr_reader source: RDocSource
5
+
6
+ attr_accessor include_arg_lists: bool
7
+ attr_accessor include_filename: bool
8
+
9
+ def initialize: (source: RDocSource) -> void
10
+
11
+ def annotate_file: (Pathname, preserve: bool) -> void
12
+
13
+ def annotate_decls: (Array[AST::Declarations::t], ?outer: Array[Namespace]) -> void
14
+
15
+ interface _PathTester
16
+ def test_path: (String) -> bool
17
+ end
18
+
19
+ interface _WithRDocComment
20
+ def comment: () -> RDoc::Markup::Document
21
+ end
22
+
23
+ def each_part: (Array[Object & _WithRDocComment], tester: _PathTester) { ([RDoc::Markup::Document, Object & _WithRDocComment]) -> void } -> void
24
+ | (Array[Object & _WithRDocComment], tester: _PathTester) -> Enumerator[[RDoc::Markup::Document, Object & _WithRDocComment], void]
25
+
26
+ def join_docs: (Array[String?], ?separator: String) -> String?
27
+
28
+ def doc_for_class: (TypeName, tester: _PathTester) -> String?
29
+
30
+ # Returns the formatted document of given method.
31
+ #
32
+ # Expands attribute documents, or alias documents if needed.
33
+ #
34
+ def doc_for_method: (TypeName, instance_method: Symbol, tester: _PathTester) -> String?
35
+ | (TypeName, singleton_method: Symbol, tester: _PathTester) -> String?
36
+
37
+
38
+ def doc_for_method0: (TypeName, instance_method: Symbol, tester: _PathTester) -> String?
39
+ | (TypeName, singleton_method: Symbol, tester: _PathTester) -> String?
40
+
41
+ # Having `require: nil` means any attribute is okay.
42
+ # Having `require: "R"` means _read attr_ is required.
43
+ # Having `require: "W"` means write attr_ is required.
44
+ #
45
+ def doc_for_attribute: (TypeName, Symbol, singleton: bool, ?require: nil | "R" | "W", tester: _PathTester) -> String?
46
+
47
+ def doc_for_alias: (TypeName, name: Symbol, singleton: bool, tester: _PathTester) -> String?
48
+
49
+ def doc_for_constant: (TypeName, tester: _PathTester) -> String?
50
+
51
+ def resolve_doc_source: (Annotations::Copy?, tester: _PathTester) { () -> String? } -> String?
52
+
53
+ def annotate_class: (AST::Declarations::Class | AST::Declarations::Module, outer: Array[Namespace]) -> void
54
+
55
+ def annotate_constant: (AST::Declarations::Constant, outer: Array[Namespace]) -> void
56
+
57
+ def annotate_method: (TypeName, AST::Members::MethodDefinition) -> void
58
+
59
+ def annotate_alias: (TypeName, AST::Members::Alias) -> void
60
+
61
+ def annotate_attribute: (TypeName, AST::Members::AttrReader | AST::Members::AttrWriter | AST::Members::AttrAccessor) -> void
62
+
63
+ def annotations: (_Annotated) -> Annotations
64
+
65
+ interface _Annotated
66
+ def annotations: -> Array[AST::Annotation]
67
+ end
68
+
69
+ # - If a string is given as `comment`, the content is attached to the object as a comment.
70
+ # - If empty string is given as `comment`, it deletes the original comment.
71
+ # - If `nil` is given as `comment`, it keeps the original comment.
72
+ #
73
+ def replace_comment: (Object & _Commented, String? comment) -> void
74
+
75
+ interface _Commented
76
+ def comment: () -> AST::Comment?
77
+ end
78
+
79
+ def resolve_name: (TypeName, outer: Array[Namespace]) -> TypeName
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,30 @@
1
+ module RBS
2
+ module Annotate
3
+ class RDocSource
4
+ attr_accessor with_system_dir: bool
5
+ attr_accessor with_gems_dir: bool
6
+ attr_accessor with_site_dir: bool
7
+ attr_accessor with_home_dir: bool
8
+
9
+ attr_reader extra_dirs: Array[Pathname]
10
+
11
+ attr_reader stores: Array[RDoc::Store]
12
+
13
+ def initialize: () -> void
14
+
15
+ def load: () -> void
16
+
17
+ # Extract documents from `CodeObject`s
18
+ def docs: () { () -> Array[RDoc::CodeObject]? } -> Array[RDoc::Markup::Document]?
19
+
20
+ def find_class: (TypeName) -> Array[RDoc::ClassModule]?
21
+
22
+ def find_const: (TypeName) -> Array[RDoc::Constant]?
23
+
24
+ def find_method: (TypeName, instance_method: Symbol) -> Array[RDoc::AnyMethod]?
25
+ | (TypeName, singleton_method: Symbol) -> Array[RDoc::AnyMethod]?
26
+
27
+ def find_attribute: (TypeName, Symbol, singleton: bool) -> Array[RDoc::Attr]?
28
+ end
29
+ end
30
+ end
data/sig/buffer.rbs CHANGED
@@ -11,12 +11,16 @@ module RBS
11
11
  # The content of the buffer.
12
12
  attr_reader content: String
13
13
 
14
- attr_reader lines: Array[String]
14
+ @lines: Array[String]
15
15
 
16
- attr_reader ranges: Array[Range[Integer]]
16
+ @ranges: Array[Range[Integer]]
17
17
 
18
18
  def initialize: (name: untyped name, content: String content) -> void
19
19
 
20
+ def lines: () -> Array[String]
21
+
22
+ def ranges: () -> Array[Range[Integer]]
23
+
20
24
  # Translate position to location.
21
25
  def pos_to_loc: (Integer pos) -> loc
22
26
 
data/sig/cli.rbs CHANGED
@@ -66,6 +66,8 @@ module RBS
66
66
 
67
67
  def run_collection: (Array[String], LibraryOptions) -> void
68
68
 
69
+ def run_annotate: (Array[String], top) -> void
70
+
69
71
  def test_opt: (LibraryOptions) -> String?
70
72
 
71
73
  def collection_options: (Array[String]) -> OptionParser
File without changes
data/sig/location.rbs CHANGED
@@ -87,6 +87,12 @@ module RBS
87
87
  def each_required_key: () { (Symbol) -> void } -> void
88
88
  | () -> Enumerator[Symbol, void]
89
89
 
90
+ def optional_key?: (Symbol) -> bool
91
+
92
+ def required_key?: (Symbol) -> bool
93
+
94
+ def key?: (Symbol) -> bool
95
+
90
96
  private
91
97
 
92
98
  def _start_loc: () -> Buffer::loc?
data/sig/members.rbs CHANGED
@@ -12,6 +12,8 @@ module RBS
12
12
  class Base
13
13
  end
14
14
 
15
+ type visibility = :public | :private
16
+
15
17
  class MethodDefinition < Base
16
18
  type kind = :instance | :singleton | :singleton_instance
17
19
 
@@ -19,13 +21,14 @@ module RBS
19
21
  # ^^^ keyword
20
22
  # ^^^ name
21
23
  #
22
- # def self.bar: () -> void | ...
23
- # ^^^ keyword
24
- # ^^^^^ kind
25
- # ^^^ name
26
- # ^^^ overload
24
+ # private def self.bar: () -> void | ...
25
+ # ^^^^^^^ visibility
26
+ # ^^^ keyword
27
+ # ^^^^^ kind
28
+ # ^^^ name
29
+ # ^^^ overload
27
30
  #
28
- type loc = Location[:keyword | :name, :kind | :overload]
31
+ type loc = Location[:keyword | :name, :kind | :overload | :visibility]
29
32
 
30
33
  attr_reader name: Symbol
31
34
  attr_reader kind: kind
@@ -34,8 +37,9 @@ module RBS
34
37
  attr_reader location: loc?
35
38
  attr_reader comment: Comment?
36
39
  attr_reader overload: bool
40
+ attr_reader visibility: visibility?
37
41
 
38
- def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: loc?, comment: Comment?, overload: boolish) -> void
42
+ def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: loc?, comment: Comment?, overload: boolish, ?visibility: visibility?) -> void
39
43
 
40
44
  include _HashEqual
41
45
  include _ToJson
@@ -46,7 +50,7 @@ module RBS
46
50
 
47
51
  def overload?: () -> bool
48
52
 
49
- def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?overload: boolish) -> MethodDefinition
53
+ def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?overload: boolish, ?visibility: visibility?) -> MethodDefinition
50
54
  end
51
55
 
52
56
  module Var
@@ -133,15 +137,16 @@ module RBS
133
137
  # ^^^^ name
134
138
  # ^ colon
135
139
  #
136
- # attr_accessor self.name (@foo) : String
137
- # ^^^^^^^^^^^^^ keyword
138
- # ^^^^^ kind
139
- # ^^^^ name
140
- # ^^^^^^ ivar
141
- # ^^^^ ivar_name
142
- # ^ colon
140
+ # public attr_accessor self.name (@foo) : String
141
+ # ^^^^^^ visibility
142
+ # ^^^^^^^^^^^^^ keyword
143
+ # ^^^^^ kind
144
+ # ^^^^ name
145
+ # ^^^^^^ ivar
146
+ # ^^^^ ivar_name
147
+ # ^ colon
143
148
  #
144
- type loc = Location[:keyword | :name | :colon, :kind | :ivar | :ivar_name]
149
+ type loc = Location[:keyword | :name | :colon, :kind | :ivar | :ivar_name | :visibility]
145
150
 
146
151
  attr_reader name: Symbol
147
152
  attr_reader type: Types::t
@@ -150,12 +155,13 @@ module RBS
150
155
  attr_reader annotations: Array[Annotation]
151
156
  attr_reader location: loc?
152
157
  attr_reader comment: Comment?
158
+ attr_reader visibility: visibility?
153
159
 
154
- def initialize: (name: Symbol, type: Types::t, ivar_name: Symbol | false | nil, kind: kind, annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
160
+ def initialize: (name: Symbol, type: Types::t, ivar_name: Symbol | false | nil, kind: kind, annotations: Array[Annotation], location: loc?, comment: Comment?, ?visibility: visibility?) -> void
155
161
 
156
162
  include _HashEqual
157
163
 
158
- def update: (?name: Symbol, ?type: Types::t, ?ivar_name: Symbol | false | nil, ?kind: kind, ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?) -> instance
164
+ def update: (?name: Symbol, ?type: Types::t, ?ivar_name: Symbol | false | nil, ?kind: kind, ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?visibility: visibility) -> instance
159
165
  end
160
166
 
161
167
  class AttrReader < Base
@@ -6,7 +6,8 @@ module RBS
6
6
 
7
7
  class Definition
8
8
  type original = AST::Members::MethodDefinition | AST::Members::Alias | AST::Members::AttrAccessor | AST::Members::AttrWriter | AST::Members::AttrReader
9
- type accessibility = :public | :private
9
+
10
+ type accessibility = RBS::Definition::accessibility
10
11
 
11
12
  attr_reader name: Symbol
12
13
  attr_reader type: instance_type
@@ -59,11 +60,11 @@ module RBS
59
60
 
60
61
  def build_interface: (TypeName) -> Methods
61
62
 
62
- def build_alias: (Methods, Methods::instance_type, member: AST::Members::Alias, accessibility: Methods::Definition::accessibility) -> void
63
+ def build_alias: (Methods, Methods::instance_type, member: AST::Members::Alias) -> void
63
64
 
64
- def build_attribute: (Methods, Methods::instance_type, member: AST::Members::AttrAccessor | AST::Members::AttrReader | AST::Members::AttrWriter, accessibility: Methods::Definition::accessibility) -> void
65
+ def build_attribute: (Methods, Methods::instance_type, member: AST::Members::AttrAccessor | AST::Members::AttrReader | AST::Members::AttrWriter, accessibility: Definition::accessibility) -> void
65
66
 
66
- def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition, accessibility: Methods::Definition::accessibility) -> void
67
+ def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition, accessibility: Definition::accessibility) -> void
67
68
 
68
69
  def each_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
69
70
 
data/sig/method_types.rbs CHANGED
@@ -7,7 +7,11 @@ module RBS
7
7
  # ^^^ type_params
8
8
  # ^^^^^^^^^^^^^^^^^^^ type
9
9
  #
10
- type loc = Location[:type, :type_params]
10
+ type def_loc = Location[:type, :type_params]
11
+
12
+ type attr_loc = AST::Members::Attribute::loc
13
+
14
+ type loc = def_loc | attr_loc
11
15
 
12
16
  attr_reader type_params: Array[AST::TypeParam]
13
17
  attr_reader type: Types::Function
data/sig/polyfill.rbs CHANGED
@@ -25,3 +25,81 @@ module Bundler
25
25
  def version: () -> String
26
26
  end
27
27
  end
28
+
29
+ module RDoc
30
+ class Store
31
+ def initialize: (?String? path, ?Symbol? type) -> void
32
+
33
+ def find_class_or_module: (String) -> ClassModule?
34
+
35
+ def load_all: () -> void
36
+ end
37
+
38
+ module RI
39
+ module Paths
40
+ type path_type = :system | :site | :home | :gem | :extra
41
+
42
+ type gem_filter = :latest | :all
43
+
44
+ def self.each: (?bool system, ?bool site, ?bool home, ?gem_filter | false gems, *String extra_dirs) { (String, path_type) -> void } -> void
45
+ end
46
+ end
47
+
48
+ class CodeObject
49
+ def comment: () -> RDoc::Markup::Document
50
+ end
51
+
52
+ class Context < CodeObject
53
+
54
+ end
55
+
56
+ class ClassModule < Context
57
+ def constants: () -> Array[Constant]
58
+
59
+ def method_list: () -> Array[AnyMethod]
60
+
61
+ def attributes: () -> Array[Attr]
62
+ end
63
+
64
+ class Constant < CodeObject
65
+ def name: () -> String
66
+ end
67
+
68
+ class AnyMethod < MethodAttr
69
+ def arglists: () -> String?
70
+
71
+ def callseq: () -> String?
72
+ end
73
+
74
+ class MethodAttr < CodeObject
75
+ attr_reader name: String
76
+
77
+ attr_reader singleton: bool
78
+
79
+ attr_reader is_alias_for: MethodAttr?
80
+
81
+ attr_reader call_seq: String
82
+
83
+ attr_reader arglists: String
84
+ end
85
+
86
+ class Attr < MethodAttr
87
+ attr_accessor rw: "RW" | "R" | "W"
88
+ end
89
+
90
+ module Markup
91
+ class Document
92
+ include Enumerable[Document]
93
+
94
+ def each: () { (Document) -> void } -> void
95
+ | () -> Enumerator[Document, void]
96
+
97
+ def file: () -> String?
98
+
99
+ def accept: (untyped) -> String
100
+ end
101
+
102
+ class ToMarkdown
103
+ end
104
+ end
105
+ end
data/sig/validator.rbs CHANGED
@@ -23,7 +23,9 @@ module RBS
23
23
  # - The generics type parameter variance annotation is consistent with respect to their usage
24
24
  # - There is no circular dependencies between the generics type parameter bounds
25
25
  #
26
- def validate_type_alias: (entry: Environment::SingleEntry[TypeName, AST::Declarations::Alias]) -> void
26
+ # It yields the rhs type if block is given, so that you can validate the rhs type.
27
+ #
28
+ def validate_type_alias: (entry: Environment::SingleEntry[TypeName, AST::Declarations::Alias]) ?{ (Types::t rhs_type) -> void } -> void
27
29
 
28
30
  # Validates the type parameters in generic methods.
29
31
  #