rbs 4.0.3 → 4.1.0.pre.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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/c-check.yml +3 -0
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/jruby.yml +67 -0
  5. data/.github/workflows/milestone.yml +4 -1
  6. data/.github/workflows/ruby.yml +40 -0
  7. data/.github/workflows/rust.yml +3 -2
  8. data/.github/workflows/truffleruby.yml +54 -0
  9. data/.github/workflows/typecheck.yml +3 -0
  10. data/.github/workflows/wasm.yml +53 -0
  11. data/.github/workflows/windows.yml +3 -0
  12. data/.gitignore +7 -0
  13. data/CHANGELOG.md +0 -8
  14. data/README.md +3 -3
  15. data/Rakefile +118 -3
  16. data/Steepfile +7 -0
  17. data/config.yml +24 -0
  18. data/core/array.rbs +144 -144
  19. data/core/builtin.rbs +7 -6
  20. data/core/class.rbs +5 -3
  21. data/core/enumerable.rbs +109 -109
  22. data/core/enumerator/product.rbs +5 -5
  23. data/core/enumerator.rbs +28 -28
  24. data/core/file.rbs +24 -1018
  25. data/core/file_constants.rbs +463 -0
  26. data/core/file_stat.rbs +534 -0
  27. data/core/hash.rbs +117 -101
  28. data/core/integer.rbs +21 -58
  29. data/core/io.rbs +25 -7
  30. data/core/kernel.rbs +26 -11
  31. data/core/module.rbs +88 -74
  32. data/core/numeric.rbs +3 -0
  33. data/core/object_space/weak_key_map.rbs +7 -7
  34. data/core/range.rbs +23 -23
  35. data/core/rbs/ops.rbs +154 -0
  36. data/core/rbs/unnamed/argf.rbs +3 -3
  37. data/core/ruby_vm.rbs +40 -0
  38. data/core/set.rbs +3 -3
  39. data/core/struct.rbs +16 -16
  40. data/core/thread.rbs +6 -6
  41. data/docs/CONTRIBUTING.md +2 -1
  42. data/docs/inline.md +65 -7
  43. data/docs/rbs_by_example.md +20 -20
  44. data/docs/syntax.md +2 -2
  45. data/docs/wasm_serialization.md +80 -0
  46. data/ext/rbs_extension/ast_translation.c +1298 -956
  47. data/ext/rbs_extension/ast_translation.h +4 -0
  48. data/ext/rbs_extension/class_constants.c +2 -0
  49. data/ext/rbs_extension/class_constants.h +1 -0
  50. data/ext/rbs_extension/extconf.rb +1 -0
  51. data/ext/rbs_extension/main.c +139 -4
  52. data/include/rbs/ast.h +323 -298
  53. data/include/rbs/defines.h +13 -0
  54. data/include/rbs/lexer.h +1 -0
  55. data/include/rbs/serialize.h +39 -0
  56. data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
  57. data/lib/rbs/ast/ruby/annotations.rb +42 -0
  58. data/lib/rbs/ast/ruby/comment_block.rb +6 -4
  59. data/lib/rbs/ast/ruby/declarations.rb +11 -1
  60. data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
  61. data/lib/rbs/ast/ruby/members.rb +40 -1
  62. data/lib/rbs/buffer.rb +48 -11
  63. data/lib/rbs/cli.rb +3 -5
  64. data/lib/rbs/collection/config/lockfile_generator.rb +14 -1
  65. data/lib/rbs/collection/sources/git.rb +6 -0
  66. data/lib/rbs/definition_builder/method_builder.rb +12 -6
  67. data/lib/rbs/environment.rb +10 -3
  68. data/lib/rbs/inline_parser.rb +54 -28
  69. data/lib/rbs/namespace.rb +47 -11
  70. data/lib/rbs/prototype/runtime.rb +2 -0
  71. data/lib/rbs/resolver/type_name_resolver.rb +12 -14
  72. data/lib/rbs/rewriter.rb +70 -0
  73. data/lib/rbs/test/type_check.rb +6 -1
  74. data/lib/rbs/type_name.rb +33 -13
  75. data/lib/rbs/unit_test/type_assertions.rb +9 -0
  76. data/lib/rbs/version.rb +1 -1
  77. data/lib/rbs/wasm/deserializer.rb +213 -0
  78. data/lib/rbs/wasm/location.rb +61 -0
  79. data/lib/rbs/wasm/parser.rb +137 -0
  80. data/lib/rbs/wasm/runtime.rb +217 -0
  81. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  82. data/lib/rbs.rb +14 -2
  83. data/rbs.gemspec +19 -2
  84. data/sig/annotate/rdoc_annotater.rbs +12 -9
  85. data/sig/ast/ruby/annotations.rbs +49 -0
  86. data/sig/ast/ruby/members.rbs +21 -1
  87. data/sig/buffer.rbs +19 -1
  88. data/sig/collection/config/lockfile_generator.rbs +2 -0
  89. data/sig/inline_parser.rbs +2 -0
  90. data/sig/manifest.yaml +0 -1
  91. data/sig/namespace.rbs +20 -0
  92. data/sig/parser.rbs +10 -0
  93. data/sig/resolver/type_name_resolver.rbs +2 -4
  94. data/sig/rewriter.rbs +45 -0
  95. data/sig/typename.rbs +15 -0
  96. data/sig/unit_test/type_assertions.rbs +4 -0
  97. data/sig/wasm/deserializer.rbs +66 -0
  98. data/sig/wasm/serialization_schema.rbs +13 -0
  99. data/src/ast.c +186 -162
  100. data/src/lexer.c +137 -114
  101. data/src/lexer.re +1 -0
  102. data/src/lexstate.c +6 -1
  103. data/src/parser.c +55 -5
  104. data/src/serialize.c +958 -0
  105. data/src/util/rbs_allocator.c +1 -4
  106. data/stdlib/abbrev/0/array.rbs +1 -1
  107. data/stdlib/csv/0/csv.rbs +5 -5
  108. data/stdlib/digest/0/digest.rbs +1 -1
  109. data/stdlib/etc/0/etc.rbs +18 -4
  110. data/stdlib/fileutils/0/fileutils.rbs +21 -21
  111. data/stdlib/json/0/json.rbs +6 -6
  112. data/stdlib/openssl/0/openssl.rbs +7 -7
  113. data/stdlib/resolv/0/resolv.rbs +1 -1
  114. data/stdlib/shellwords/0/shellwords.rbs +1 -1
  115. data/stdlib/stringio/0/stringio.rbs +32 -10
  116. data/stdlib/strscan/0/string_scanner.rbs +74 -55
  117. data/stdlib/tsort/0/cyclic.rbs +1 -1
  118. data/stdlib/tsort/0/interfaces.rbs +8 -8
  119. data/stdlib/tsort/0/tsort.rbs +9 -9
  120. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  121. data/wasm/README.md +59 -0
  122. data/wasm/rbs_wasm.c +411 -0
  123. metadata +23 -5
  124. data/.vscode/extensions.json +0 -5
  125. data/.vscode/settings.json +0 -19
@@ -83,4 +83,17 @@
83
83
  #define RBS_ATTRIBUTE_UNUSED
84
84
  #endif
85
85
 
86
+ /**
87
+ * Nullability annotations for pointer types.
88
+ * Clang supports _Nullable and _Nonnull to indicate whether a pointer may be NULL.
89
+ * On other compilers, these expand to nothing.
90
+ */
91
+ #ifdef __clang__
92
+ #define RBS_NULLABLE _Nullable
93
+ #define RBS_NONNULL _Nonnull
94
+ #else
95
+ #define RBS_NULLABLE
96
+ #define RBS_NONNULL
97
+ #endif
98
+
86
99
  #endif
data/include/rbs/lexer.h CHANGED
@@ -70,6 +70,7 @@ enum RBSTokenType {
70
70
  kATRBS, /* @rbs */
71
71
  kSKIP, /* skip */
72
72
  kRETURN, /* return */
73
+ kMODULESELF, /* module-self */
73
74
 
74
75
  tLIDENT, /* Identifiers starting with lower case */
75
76
  tUIDENT, /* Identifiers starting with upper case */
@@ -0,0 +1,39 @@
1
+ /*----------------------------------------------------------------------------*/
2
+ /* This file is generated by the templates/template.rb script and should not */
3
+ /* be modified manually. */
4
+ /* To change the template see */
5
+ /* templates/include/rbs/serialize.h.erb */
6
+ /*----------------------------------------------------------------------------*/
7
+
8
+ #ifndef RBS__SERIALIZE_H
9
+ #define RBS__SERIALIZE_H
10
+
11
+ #include "rbs/ast.h"
12
+ #include "rbs/string.h"
13
+ #include "rbs/util/rbs_allocator.h"
14
+ #include "rbs/util/rbs_constant_pool.h"
15
+
16
+ /**
17
+ * Serialize a parsed AST node into a compact, portable binary buffer.
18
+ *
19
+ * The format is consumed by RBS::WASM::Deserializer on the Ruby side, which
20
+ * rebuilds the same `RBS::AST` objects that the C extension would have built
21
+ * directly. This is what lets RBS run on Ruby implementations that cannot load
22
+ * the C extension (notably JRuby): the parser runs inside WebAssembly, produces
23
+ * this buffer, and the host reconstructs the tree in pure Ruby.
24
+ *
25
+ * The buffer is allocated from `allocator`, so its lifetime is tied to that
26
+ * allocator. `constant_pool` must be the pool the node was parsed with; it is
27
+ * used to resolve interned symbol/identifier ids back into their bytes.
28
+ *
29
+ * See `docs/wasm_serialization.md` for the wire format.
30
+ */
31
+ rbs_string_t rbs_serialize_node(rbs_allocator_t *allocator, rbs_constant_pool_t *constant_pool, rbs_node_t *node);
32
+
33
+ /**
34
+ * Like rbs_serialize_node, but for a bare node list (e.g. the result of
35
+ * rbs_parse_type_params). Decoded by RBS::WASM::Deserializer.deserialize_node_list.
36
+ */
37
+ rbs_string_t rbs_serialize_node_list(rbs_allocator_t *allocator, rbs_constant_pool_t *constant_pool, rbs_node_list_t *list);
38
+
39
+ #endif
@@ -13,25 +13,22 @@ module RBS
13
13
  @include_filename = true
14
14
  end
15
15
 
16
- def annotate_file(path, preserve:)
17
- content = path.read()
16
+ def annotate_file(path, preserve: true)
17
+ buffer, _, decls = Parser.parse_signature(path.read())
18
18
 
19
- _, _, decls = Parser.parse_signature(content)
19
+ rewriter = Rewriter.new(buffer)
20
+ annotate_decls(decls, rewriter)
20
21
 
21
- annotate_decls(decls)
22
-
23
- path.open("w") do |io|
24
- Writer.new(out: io).preserve!(preserve: preserve).write(decls)
25
- end
22
+ path.write(rewriter.string)
26
23
  end
27
24
 
28
- def annotate_decls(decls, outer: [])
25
+ def annotate_decls(decls, rewriter, outer: [])
29
26
  decls.each do |decl|
30
27
  case decl
31
28
  when AST::Declarations::Class, AST::Declarations::Module
32
- annotate_class(decl, outer: outer)
29
+ annotate_class(decl, rewriter, outer: outer)
33
30
  when AST::Declarations::Constant
34
- annotate_constant(decl, outer: outer)
31
+ annotate_constant(decl, rewriter, outer: outer)
35
32
  end
36
33
  end
37
34
  end
@@ -244,7 +241,7 @@ module RBS
244
241
  end
245
242
  end
246
243
 
247
- def annotate_class(decl, outer:)
244
+ def annotate_class(decl, rewriter, outer:)
248
245
  annots = annotations(decl)
249
246
 
250
247
  full_name = resolve_name(decl.name, outer: outer)
@@ -252,7 +249,7 @@ module RBS
252
249
  text = resolve_doc_source(annots.copy_annotation, tester: annots) { doc_for_class(full_name, tester: annots) }
253
250
  end
254
251
 
255
- replace_comment(decl, text)
252
+ replace_comment(decl, text, rewriter)
256
253
 
257
254
  unless annots.skip_all?
258
255
  outer_ = outer + [decl.name.to_namespace]
@@ -260,28 +257,28 @@ module RBS
260
257
  decl.each_member do |member|
261
258
  case member
262
259
  when AST::Members::MethodDefinition
263
- annotate_method(full_name, member)
260
+ annotate_method(full_name, member, rewriter)
264
261
  when AST::Members::Alias
265
- annotate_alias(full_name, member)
262
+ annotate_alias(full_name, member, rewriter)
266
263
  when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
267
- annotate_attribute(full_name, member)
264
+ annotate_attribute(full_name, member, rewriter)
268
265
  end
269
266
  end
270
267
 
271
- annotate_decls(decl.each_decl.to_a, outer: outer_)
268
+ annotate_decls(decl.each_decl.to_a, rewriter, outer: outer_)
272
269
  end
273
270
  end
274
271
 
275
- def annotate_constant(const, outer:)
272
+ def annotate_constant(const, rewriter, outer:)
276
273
  annots = Annotations.new([])
277
274
 
278
275
  full_name = resolve_name(const.name, outer: outer)
279
276
  text = doc_for_constant(full_name, tester: annots)
280
277
 
281
- replace_comment(const, text)
278
+ replace_comment(const, text, rewriter)
282
279
  end
283
280
 
284
- def annotate_alias(typename, als)
281
+ def annotate_alias(typename, als, rewriter)
285
282
  annots = annotations(als)
286
283
 
287
284
  unless annots.skip?
@@ -295,7 +292,7 @@ module RBS
295
292
  end
296
293
  end
297
294
 
298
- replace_comment(als, text)
295
+ replace_comment(als, text, rewriter)
299
296
  end
300
297
 
301
298
  def join_docs(docs, separator: "----")
@@ -311,7 +308,7 @@ module RBS
311
308
  end
312
309
  end
313
310
 
314
- def annotate_method(typename, method)
311
+ def annotate_method(typename, method, rewriter)
315
312
  annots = annotations(method)
316
313
 
317
314
  unless annots.skip?
@@ -337,10 +334,10 @@ module RBS
337
334
  }
338
335
  end
339
336
 
340
- replace_comment(method, text)
337
+ replace_comment(method, text, rewriter)
341
338
  end
342
339
 
343
- def annotate_attribute(typename, attr)
340
+ def annotate_attribute(typename, attr, rewriter)
344
341
  annots = annotations(attr)
345
342
 
346
343
  unless annots.skip?
@@ -368,18 +365,17 @@ module RBS
368
365
  end
369
366
  end
370
367
 
371
- replace_comment(attr, text)
368
+ replace_comment(attr, text, rewriter)
372
369
  end
373
370
 
374
- def replace_comment(commented, string)
371
+ def replace_comment(commented, string, rewriter)
375
372
  if string
376
373
  if string.empty?
377
- commented.instance_variable_set(:@comment, nil)
374
+ rewriter.delete_comment(commented.comment) if commented.comment
375
+ elsif commented.comment
376
+ rewriter.replace_comment(commented.comment, content: string)
378
377
  else
379
- commented.instance_variable_set(
380
- :@comment,
381
- AST::Comment.new(location: nil, string: string)
382
- )
378
+ rewriter.add_comment(commented.location || raise, *commented.annotations.filter_map(&:location), content: string)
383
379
  end
384
380
  end
385
381
  end
@@ -353,6 +353,48 @@ module RBS
353
353
  end
354
354
  end
355
355
 
356
+ class ModuleSelfAnnotation < Base
357
+ attr_reader :keyword_location, :colon_location, :name, :args, :open_bracket_location, :close_bracket_location, :args_comma_locations, :comment_location
358
+
359
+ def initialize(location:, prefix_location:, keyword_location:, colon_location:, name:, args:, open_bracket_location:, close_bracket_location:, args_comma_locations:, comment_location:)
360
+ super(location, prefix_location)
361
+ @keyword_location = keyword_location
362
+ @colon_location = colon_location
363
+ @name = name
364
+ @args = args
365
+ @open_bracket_location = open_bracket_location
366
+ @close_bracket_location = close_bracket_location
367
+ @args_comma_locations = args_comma_locations
368
+ @comment_location = comment_location
369
+ end
370
+
371
+ def map_type_name
372
+ mapped_args = args.map { |type| type.map_type_name { yield _1 } }
373
+
374
+ self.class.new(
375
+ location:,
376
+ prefix_location:,
377
+ keyword_location:,
378
+ colon_location:,
379
+ name: yield(name),
380
+ args: mapped_args,
381
+ open_bracket_location:,
382
+ close_bracket_location:,
383
+ args_comma_locations:,
384
+ comment_location:
385
+ ) #: self
386
+ end
387
+
388
+ def type_fingerprint
389
+ [
390
+ "annots/module_self",
391
+ name.to_s,
392
+ args.map(&:to_s),
393
+ comment_location&.source
394
+ ]
395
+ end
396
+ end
397
+
356
398
  class BlockParamTypeAnnotation < Base
357
399
  attr_reader :ampersand_location, :name_location, :colon_location, :question_location, :type_location, :type, :comment_location
358
400
 
@@ -15,6 +15,7 @@ module RBS
15
15
  prefix_str = "# "
16
16
 
17
17
  ranges = [] #: Array[Range[Integer]]
18
+ byte_ranges = [] #: Array[Range[Integer]]
18
19
 
19
20
  comments.each do |comment|
20
21
  tuple = [comment, 2] #: [Prism::Comment, Integer]
@@ -25,12 +26,13 @@ module RBS
25
26
 
26
27
  offsets << tuple
27
28
 
28
- start_char = comment.location.start_character_offset + tuple[1]
29
- end_char = comment.location.end_character_offset
29
+ start_char = source_buffer.character_offset(comment.location.start_offset) + tuple[1]
30
+ end_char = source_buffer.character_offset(comment.location.end_offset)
30
31
  ranges << (start_char ... end_char)
32
+ byte_ranges << ((comment.location.start_offset + tuple[1]) ... comment.location.end_offset)
31
33
  end
32
34
 
33
- @comment_buffer = source_buffer.sub_buffer(lines: ranges)
35
+ @comment_buffer = source_buffer.sub_buffer(lines: ranges, byte_lines_hint: byte_ranges)
34
36
  end
35
37
 
36
38
  def leading?
@@ -53,7 +55,7 @@ module RBS
53
55
 
54
56
  def line_starts
55
57
  offsets.map do |comment, prefix_size|
56
- comment.location.start_character_offset + prefix_size
58
+ comment_buffer.character_offset(comment.location.start_offset) + prefix_size
57
59
  end
58
60
  end
59
61
 
@@ -137,7 +137,17 @@ module RBS
137
137
 
138
138
  def type_params = []
139
139
 
140
- def self_types = []
140
+ def self_types
141
+ members.filter_map do |member|
142
+ if member.is_a?(Members::ModuleSelfMember)
143
+ AST::Declarations::Module::Self.new(
144
+ name: member.name,
145
+ args: member.args,
146
+ location: member.location
147
+ )
148
+ end
149
+ end
150
+ end
141
151
 
142
152
  def location
143
153
  rbs_location(node.location)
@@ -6,7 +6,7 @@ module RBS
6
6
  module Helpers
7
7
  module LocationHelper
8
8
  def rbs_location(location)
9
- Location.new(buffer, location.start_character_offset, location.end_character_offset)
9
+ Location.new(buffer, buffer.character_offset(location.start_offset), buffer.character_offset(location.end_offset))
10
10
  end
11
11
  end
12
12
  end
@@ -549,17 +549,27 @@ module RBS
549
549
 
550
550
  attr_reader :name
551
551
  attr_reader :node
552
+ attr_reader :kind
552
553
  attr_reader :method_type
553
554
  attr_reader :leading_comment
554
555
 
555
- def initialize(buffer, name, node, method_type, leading_comment)
556
+ def initialize(buffer, name, node, method_type, leading_comment, kind: :instance)
556
557
  super(buffer)
557
558
  @name = name
558
559
  @node = node
560
+ @kind = kind
559
561
  @method_type = method_type
560
562
  @leading_comment = leading_comment
561
563
  end
562
564
 
565
+ def singleton?
566
+ kind == :singleton
567
+ end
568
+
569
+ def instance?
570
+ kind == :instance
571
+ end
572
+
563
573
  def location
564
574
  rbs_location(node.location)
565
575
  end
@@ -583,6 +593,7 @@ module RBS
583
593
  def type_fingerprint
584
594
  [
585
595
  "members/def",
596
+ kind.to_s,
586
597
  name.to_s,
587
598
  method_type.type_fingerprint,
588
599
  leading_comment&.as_comment&.string
@@ -717,6 +728,34 @@ module RBS
717
728
  ]
718
729
  end
719
730
  end
731
+
732
+ class ModuleSelfMember < Base
733
+ attr_reader :annotation
734
+
735
+ def initialize(buffer, annotation)
736
+ super(buffer)
737
+ @annotation = annotation
738
+ end
739
+
740
+ def name
741
+ annotation.name
742
+ end
743
+
744
+ def args
745
+ annotation.args
746
+ end
747
+
748
+ def location
749
+ annotation.location
750
+ end
751
+
752
+ def type_fingerprint
753
+ [
754
+ "members/module_self",
755
+ annotation.type_fingerprint
756
+ ]
757
+ end
758
+ end
720
759
  end
721
760
  end
722
761
  end
data/lib/rbs/buffer.rb CHANGED
@@ -87,25 +87,62 @@ module RBS
87
87
  "#<RBS::Buffer:#{__id__} @name=#{name}, @content=#{content.bytesize} bytes, @lines=#{ranges.size} lines,>"
88
88
  end
89
89
 
90
+ def character_offset(byte_offset)
91
+ top = top_buffer
92
+ return top.character_offset(byte_offset) unless top.equal?(self)
93
+
94
+ keys, vals = (@character_offset_cache ||= [[0], [0]])
95
+
96
+ idx = keys.bsearch_index { |k| k > byte_offset }
97
+ lo = idx ? idx - 1 : keys.size - 1
98
+
99
+ base_byte = keys[lo]
100
+ base_char = vals[lo]
101
+ delta = byte_offset - base_byte
102
+ return base_char if delta == 0
103
+
104
+ result = base_char + (content.byteslice(base_byte, delta) or raise).length
105
+
106
+ if base_byte == keys[-1]
107
+ keys << byte_offset
108
+ vals << result
109
+ end
110
+
111
+ result
112
+ end
113
+
90
114
  def rbs_location(location, loc2=nil)
115
+ top = top_buffer
91
116
  if loc2
92
- Location.new(self.top_buffer, location.start_character_offset, loc2.end_character_offset)
117
+ Location.new(top, character_offset(location.start_offset), character_offset(loc2.end_offset))
93
118
  else
94
- Location.new(self.top_buffer, location.start_character_offset, location.end_character_offset)
119
+ Location.new(top, character_offset(location.start_offset), character_offset(location.end_offset))
95
120
  end
96
121
  end
97
122
 
98
- def sub_buffer(lines:)
123
+ def sub_buffer(lines:, byte_lines_hint: nil)
99
124
  buf = +""
100
- lines.each_with_index do |range, index|
101
- start_pos = range.begin
102
- end_pos = range.end
103
- slice = content[start_pos...end_pos] or raise
104
- if slice.include?("\n")
105
- raise "Line #{index + 1} cannot contain newline character."
125
+
126
+ if byte_lines_hint
127
+ byte_lines_hint.each_with_index do |range, index|
128
+ slice = content.byteslice(range.begin, range.end - range.begin) or raise
129
+ if slice.include?("\n")
130
+ raise "Line #{index + 1} cannot contain newline character."
131
+ end
132
+ buf << slice
133
+ buf << "\n"
134
+ end
135
+ else
136
+ lines.each_with_index do |range, index|
137
+ start_pos = range.begin
138
+ end_pos = range.end
139
+ slice = content[start_pos...end_pos] or raise
140
+ if slice.include?("\n")
141
+ raise "Line #{index + 1} cannot contain newline character."
142
+ end
143
+ buf << slice
144
+ buf << "\n"
106
145
  end
107
- buf << slice
108
- buf << "\n"
109
146
  end
110
147
 
111
148
  buf.chomp!
data/lib/rbs/cli.rb CHANGED
@@ -962,8 +962,6 @@ Options:
962
962
  source = RBS::Annotate::RDocSource.new()
963
963
  annotator = RBS::Annotate::RDocAnnotator.new(source: source)
964
964
 
965
- preserve = true
966
-
967
965
  OptionParser.new do |opts|
968
966
  opts.banner = <<-EOB
969
967
  Usage: rbs annotate [options...] [files...]
@@ -984,7 +982,7 @@ Options:
984
982
  opts.on("-d", "--dir DIRNAME", "Load RDoc from DIRNAME") {|d| source.extra_dirs << Pathname(d) }
985
983
  opts.on("--[no-]arglists", "Generate arglists section (defaults to true)") {|b| annotator.include_arg_lists = b }
986
984
  opts.on("--[no-]filename", "Include source file name in the documentation (defaults to true)") {|b| annotator.include_filename = b }
987
- opts.on("--[no-]preserve", "Try preserve the format of the original file (defaults to true)") {|b| preserve = b }
985
+ opts.on("--[no-]preserve", "[Deprecated] It always preserves the format") { stdout.puts "The `--preserve` option is deprecated. The tool always preserves the format of RBS files." }
988
986
  end.parse!(args)
989
987
 
990
988
  source.load()
@@ -994,11 +992,11 @@ Options:
994
992
  if path.directory?
995
993
  Pathname.glob((path + "**/*.rbs").to_s).each do |path|
996
994
  stdout.puts "Processing #{path}..."
997
- annotator.annotate_file(path, preserve: preserve)
995
+ annotator.annotate_file(path)
998
996
  end
999
997
  else
1000
998
  stdout.puts "Processing #{path}..."
1001
- annotator.annotate_file(path, preserve: preserve)
999
+ annotator.annotate_file(path)
1002
1000
  end
1003
1001
  end
1004
1002
 
@@ -21,6 +21,17 @@ module RBS
21
21
  "pstore" => nil,
22
22
  }
23
23
 
24
+ NONGEM_STDLIBS = Set[
25
+ "cgi-escape",
26
+ "coverage",
27
+ "monitor",
28
+ "objspace",
29
+ "pathname",
30
+ "pty",
31
+ "ripper",
32
+ "socket",
33
+ ]
34
+
24
35
  class GemfileLockMismatchError < StandardError
25
36
  def initialize(expected:, actual:)
26
37
  @expected = expected
@@ -168,7 +179,9 @@ module RBS
168
179
  end
169
180
  end
170
181
  else
171
- RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
182
+ unless NONGEM_STDLIBS.include?(name)
183
+ RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
184
+ end
172
185
  end
173
186
  end
174
187
 
@@ -140,6 +140,12 @@ module RBS
140
140
  # git v2.27.0 or greater
141
141
  git 'clone', '--filter=blob:none', remote, git_dir.to_s, chdir: nil
142
142
  rescue CommandError
143
+ # The failed `--filter=blob:none` clone may leave behind a
144
+ # partial repository (e.g. when the server returned an error
145
+ # mid-clone), which would cause the fallback `git clone` to
146
+ # fail with "destination path ... already exists and is not
147
+ # an empty directory". Clean it up before retrying.
148
+ FileUtils.rm_rf(git_dir)
143
149
  git 'clone', remote, git_dir.to_s, chdir: nil
144
150
  end
145
151
  end
@@ -143,12 +143,14 @@ module RBS
143
143
  decl.members.each do |member|
144
144
  case member
145
145
  when AST::Ruby::Members::DefMember
146
- build_method(
147
- methods,
148
- type,
149
- member: member,
150
- accessibility: :public
151
- )
146
+ if member.instance?
147
+ build_method(
148
+ methods,
149
+ type,
150
+ member: member,
151
+ accessibility: :public
152
+ )
153
+ end
152
154
  when AST::Ruby::Members::AttrReaderMember, AST::Ruby::Members::AttrWriterMember, AST::Ruby::Members::AttrAccessorMember
153
155
  build_ruby_attribute(methods, type, member: member, accessibility: :public)
154
156
  end
@@ -181,6 +183,10 @@ module RBS
181
183
  if member.kind == :singleton
182
184
  build_alias(methods, type, member: member)
183
185
  end
186
+ when AST::Ruby::Members::DefMember
187
+ if member.singleton?
188
+ build_method(methods, type, member: member, accessibility: :public)
189
+ end
184
190
  end
185
191
  end
186
192
  end
@@ -173,7 +173,7 @@ module RBS
173
173
  unless type_name.namespace.empty?
174
174
  parent = type_name.namespace.to_type_name
175
175
  normalized_parent = normalize_module_name?(parent) or return
176
- constant_name = TypeName.new(name: type_name.name, namespace: normalized_parent.to_namespace)
176
+ constant_name = TypeName[normalized_parent.to_namespace, type_name.name]
177
177
  constant_decls.fetch(constant_name, nil)
178
178
  end
179
179
  end
@@ -193,7 +193,7 @@ module RBS
193
193
  parent = normalize_module_name?(parent)
194
194
  return parent unless parent
195
195
 
196
- TypeName.new(namespace: parent.to_namespace, name: name.name)
196
+ TypeName[parent.to_namespace, name.name]
197
197
  else
198
198
  name
199
199
  end
@@ -795,7 +795,8 @@ module RBS
795
795
  member.name,
796
796
  member.node,
797
797
  member.method_type.map_type_name {|name, _, _| absolute_type_name(resolver, nil, name, context: context) },
798
- member.leading_comment
798
+ member.leading_comment,
799
+ kind: member.kind
799
800
  )
800
801
  when AST::Ruby::Members::IncludeMember
801
802
  resolved_annotation = member.annotation&.map_type_name {|name, _, _| absolute_type_name(resolver, nil, name, context: context) }
@@ -854,6 +855,12 @@ module RBS
854
855
  member.buffer,
855
856
  resolved_annotation
856
857
  )
858
+ when AST::Ruby::Members::ModuleSelfMember
859
+ resolved_annotation = member.annotation.map_type_name {|name| absolute_type_name(resolver, nil, name, context: context) }
860
+ AST::Ruby::Members::ModuleSelfMember.new(
861
+ member.buffer,
862
+ resolved_annotation
863
+ )
857
864
  else
858
865
  raise "Unknown member type: #{member.class}"
859
866
  end