rbs 3.10.0 → 4.0.0.dev.1

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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
@@ -51,7 +51,7 @@ module RBS
51
51
  dirs << path
52
52
  when library
53
53
  case library
54
- when 'pathname'
54
+ when 'rubygems', 'set'
55
55
  RBS.logger.warn "`#{library}` has been moved to core library, so it is always loaded. Remove explicit loading `#{library}`"
56
56
  return
57
57
  end
@@ -122,7 +122,7 @@ module RBS
122
122
  decls.each do |decl|
123
123
  loaded << [decl, path, source]
124
124
  end
125
- env.add_signature(buffer: buffer, directives: dirs, decls: decls)
125
+ env.add_source(Source::RBS.new(buffer, dirs, decls))
126
126
  end
127
127
 
128
128
  loaded
@@ -161,7 +161,7 @@ module RBS
161
161
  next if files.include?(path)
162
162
 
163
163
  files << path
164
- buffer = Buffer.new(name: path.to_s, content: path.read(encoding: "UTF-8"))
164
+ buffer = Buffer.new(name: path, content: path.read(encoding: "UTF-8"))
165
165
 
166
166
  _, dirs, decls = Parser.parse_signature(buffer)
167
167
 
data/lib/rbs/errors.rb CHANGED
@@ -93,7 +93,7 @@ module RBS
93
93
  params =
94
94
  case
95
95
  when type_name.class?
96
- decl = env.module_class_entry(type_name, normalized: true) or raise
96
+ decl = env.normalized_module_class_entry(type_name) or raise
97
97
  decl.type_params
98
98
  when type_name.interface?
99
99
  env.interface_decls.fetch(type_name).decl.type_params
@@ -371,7 +371,7 @@ module RBS
371
371
  def initialize(name:, entry:)
372
372
  @name = name
373
373
  @entry = entry
374
- super "#{Location.to_string entry.primary.decl.location}: Superclass mismatch: #{name}"
374
+ super "#{Location.to_string entry.primary_decl.location}: Superclass mismatch: #{name}"
375
375
  end
376
376
  end
377
377
 
@@ -408,10 +408,11 @@ module RBS
408
408
  attr_reader :name
409
409
  attr_reader :decl
410
410
 
411
- def initialize(name:, decl:)
411
+ def initialize(name:, decl:, location: nil)
412
412
  @name = name
413
413
  @decl = decl
414
- super "#{Location.to_string decl.location}: Generic parameters mismatch: #{name}"
414
+ location ||= decl.location
415
+ super "#{Location.to_string location}: Generic parameters mismatch: #{name}"
415
416
  end
416
417
  end
417
418
 
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ class InlineParser
5
+ class CommentAssociation
6
+ attr_reader :blocks, :associated_blocks, :start_line_map, :end_line_map
7
+
8
+ def initialize(blocks)
9
+ @blocks = blocks.sort_by {|block| block.start_line }
10
+ @associated_blocks = Set[].compare_by_identity
11
+
12
+ @start_line_map = {}
13
+ @end_line_map = {}
14
+
15
+ blocks.each do |block|
16
+ if block.leading?
17
+ end_line_map[block.end_line] = block
18
+ else
19
+ start_line_map[block.start_line] = block
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.build(buffer, result)
25
+ blocks = AST::Ruby::CommentBlock.build(buffer, result.comments)
26
+ new(blocks)
27
+ end
28
+
29
+ class Reference
30
+ attr_reader :block
31
+
32
+ def initialize(block, association)
33
+ @block = block
34
+ @associated_blocks = association
35
+ end
36
+
37
+ def associate!
38
+ @associated_blocks << block
39
+ self
40
+ end
41
+
42
+ def associated?
43
+ @associated_blocks.include?(block)
44
+ end
45
+ end
46
+
47
+ def leading_block(node)
48
+ start_line = node.location.start_line
49
+
50
+ if block = end_line_map.fetch(start_line - 1, nil)
51
+ Reference.new(block, associated_blocks)
52
+ end
53
+ end
54
+
55
+ def leading_block!(node)
56
+ if ref = leading_block(node)
57
+ unless ref.associated?
58
+ ref.associate!.block
59
+ end
60
+ end
61
+ end
62
+
63
+ def trailing_block(node)
64
+ location =
65
+ if node.is_a?(Prism::Node)
66
+ node.location
67
+ else
68
+ node
69
+ end #: Prism::Location
70
+ end_line = location.end_line
71
+ if block = start_line_map.fetch(end_line, nil)
72
+ Reference.new(block, associated_blocks)
73
+ end
74
+ end
75
+
76
+ def trailing_block!(node)
77
+ if ref = trailing_block(node)
78
+ unless ref.associated?
79
+ ref.associate!.block
80
+ end
81
+ end
82
+ end
83
+
84
+ def each_enclosed_block(node)
85
+ if block_given?
86
+ start_line = node.location.start_line
87
+ end_line = node.location.end_line
88
+
89
+ if start_line+1 < end_line
90
+ ((start_line + 1)...end_line).each do |line|
91
+ if block = end_line_map.fetch(line, nil)
92
+ unless associated_blocks.include?(block)
93
+ associated_blocks << block
94
+ yield block
95
+ end
96
+ end
97
+ end
98
+ end
99
+ else
100
+ enum_for :each_enclosed_block, node
101
+ end
102
+ end
103
+
104
+ def each_unassociated_block
105
+ if block_given?
106
+ blocks.each do |block|
107
+ unless associated_blocks.include?(block)
108
+ yield block
109
+ end
110
+ end
111
+ else
112
+ enum_for :each_unassociated_block
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,206 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ class InlineParser
5
+ class Result
6
+ attr_reader :buffer, :prism_result, :declarations, :diagnostics
7
+
8
+ def initialize(buffer, prism)
9
+ @buffer = buffer
10
+ @prism_result = prism
11
+ @declarations = []
12
+ @diagnostics = []
13
+ end
14
+ end
15
+
16
+ module Diagnostic
17
+ class Base
18
+ attr_reader :message, :location
19
+
20
+ def initialize(location, message)
21
+ @location = location
22
+ @message = message
23
+ end
24
+ end
25
+
26
+ NotImplementedYet = _ = Class.new(Base)
27
+ NonConstantClassName = _ = Class.new(Base)
28
+ NonConstantModuleName = _ = Class.new(Base)
29
+ TopLevelMethodDefinition = _ = Class.new(Base)
30
+ UnusedInlineAnnotation = _ = Class.new(Base)
31
+ AnnotationSyntaxError = _ = Class.new(Base)
32
+ end
33
+
34
+ def self.parse(buffer, prism)
35
+ result = Result.new(buffer, prism)
36
+
37
+ Parser.new(result).visit(prism.value)
38
+
39
+ result
40
+ end
41
+
42
+ class Parser < Prism::Visitor
43
+ attr_reader :module_nesting, :result, :comments
44
+
45
+ include AST::Ruby::Helpers::ConstantHelper
46
+ include AST::Ruby::Helpers::LocationHelper
47
+
48
+ def initialize(result)
49
+ @result = result
50
+ @module_nesting = []
51
+ @comments = CommentAssociation.build(result.buffer, result.prism_result)
52
+ end
53
+
54
+ def buffer
55
+ result.buffer
56
+ end
57
+
58
+ def current_module
59
+ module_nesting.last
60
+ end
61
+
62
+ def current_module!
63
+ current_module || raise("#current_module is nil")
64
+ end
65
+
66
+ def diagnostics
67
+ result.diagnostics
68
+ end
69
+
70
+ def push_module_nesting(mod)
71
+ module_nesting.push(mod)
72
+ yield
73
+ ensure
74
+ module_nesting.pop()
75
+ end
76
+
77
+ def skip_node?(node)
78
+ if ref = comments.leading_block(node)
79
+ if ref.block.each_paragraph([]).any? { _1.is_a?(AST::Ruby::Annotations::SkipAnnotation) }
80
+ ref.associate!
81
+ return true
82
+ end
83
+ end
84
+
85
+ false
86
+ end
87
+
88
+ def visit_class_node(node)
89
+ return if skip_node?(node)
90
+
91
+ unless class_name = constant_as_type_name(node.constant_path)
92
+ diagnostics << Diagnostic::NonConstantClassName.new(
93
+ rbs_location(node.constant_path.location),
94
+ "Class name must be a constant"
95
+ )
96
+ return
97
+ end
98
+
99
+ class_decl = AST::Ruby::Declarations::ClassDecl.new(buffer, class_name, node)
100
+ insert_declaration(class_decl)
101
+ push_module_nesting(class_decl) do
102
+ visit_child_nodes(node)
103
+ end
104
+
105
+ comments.each_enclosed_block(node) do |block|
106
+ report_unused_block(block)
107
+ end
108
+ end
109
+
110
+ def visit_module_node(node)
111
+ return if skip_node?(node)
112
+
113
+ unless module_name = constant_as_type_name(node.constant_path)
114
+ diagnostics << Diagnostic::NonConstantModuleName.new(
115
+ rbs_location(node.constant_path.location),
116
+ "Module name must be a constant"
117
+ )
118
+ return
119
+ end
120
+
121
+ module_decl = AST::Ruby::Declarations::ModuleDecl.new(buffer, module_name, node)
122
+ insert_declaration(module_decl)
123
+ push_module_nesting(module_decl) do
124
+ visit_child_nodes(node)
125
+ end
126
+
127
+ comments.each_enclosed_block(node) do |block|
128
+ report_unused_block(block)
129
+ end
130
+ end
131
+
132
+ def visit_def_node(node)
133
+ return if skip_node?(node)
134
+
135
+ if node.receiver
136
+ diagnostics << Diagnostic::NotImplementedYet.new(
137
+ rbs_location(node.receiver.location),
138
+ "Singleton method definition is not supported yet"
139
+ )
140
+ return
141
+ end
142
+
143
+ case current = current_module
144
+ when AST::Ruby::Declarations::ClassDecl, AST::Ruby::Declarations::ModuleDecl
145
+ leading_block = comments.leading_block!(node)
146
+
147
+ if node.end_keyword_loc
148
+ # Not an end-less def
149
+ end_loc = node.rparen_loc || node.parameters&.location || node.name_loc
150
+ trailing_block = comments.trailing_block!(end_loc)
151
+ end
152
+
153
+ method_type, leading_unuseds, trailing_unused = AST::Ruby::Members::MethodTypeAnnotation.build(leading_block, trailing_block, [])
154
+ report_unused_annotation(trailing_unused, *leading_unuseds)
155
+
156
+ defn = AST::Ruby::Members::DefMember.new(buffer, node.name, node, method_type)
157
+ current.members << defn
158
+
159
+ # Skip other comments in `def` node
160
+ comments.each_enclosed_block(node) do |block|
161
+ comments.associated_blocks << block
162
+ end
163
+ else
164
+ diagnostics << Diagnostic::TopLevelMethodDefinition.new(
165
+ rbs_location(node.name_loc),
166
+ "Top-level method definition is not supported"
167
+ )
168
+ end
169
+ end
170
+
171
+ def insert_declaration(decl)
172
+ if current_module
173
+ current_module.members << decl
174
+ else
175
+ result.declarations << decl
176
+ end
177
+ end
178
+
179
+ def report_unused_annotation(*annotations)
180
+ annotations.each do |annotation|
181
+ case annotation
182
+ when AST::Ruby::CommentBlock::AnnotationSyntaxError
183
+ diagnostics << Diagnostic::AnnotationSyntaxError.new(
184
+ annotation.location, "Syntax error: " + annotation.error.error_message
185
+ )
186
+ when AST::Ruby::Annotations::Base
187
+ diagnostics << Diagnostic::UnusedInlineAnnotation.new(
188
+ annotation.location, "Unused inline rbs annotation"
189
+ )
190
+ end
191
+ end
192
+ end
193
+
194
+ def report_unused_block(block)
195
+ block.each_paragraph([]) do |paragraph|
196
+ case paragraph
197
+ when Location
198
+ # noop
199
+ else
200
+ report_unused_annotation(paragraph)
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
@@ -28,6 +28,14 @@ module RBS
28
28
 
29
29
  WithChildren = self
30
30
 
31
+ def start_pos
32
+ buffer.absolute_position(_start_pos) || raise
33
+ end
34
+
35
+ def end_pos
36
+ buffer.absolute_position(_end_pos) || raise
37
+ end
38
+
31
39
  def name
32
40
  buffer.name
33
41
  end
@@ -49,11 +57,11 @@ module RBS
49
57
  end
50
58
 
51
59
  def start_loc
52
- @start_loc ||= buffer.pos_to_loc(start_pos)
60
+ @start_loc ||= buffer.top_buffer.pos_to_loc(start_pos)
53
61
  end
54
62
 
55
63
  def end_loc
56
- @end_loc ||= buffer.pos_to_loc(end_pos)
64
+ @end_loc ||= buffer.top_buffer.pos_to_loc(end_pos)
57
65
  end
58
66
 
59
67
  def range
@@ -61,7 +69,7 @@ module RBS
61
69
  end
62
70
 
63
71
  def source
64
- @source ||= (buffer.content[range] || raise)
72
+ @source ||= (buffer.top_buffer.content[range] || raise)
65
73
  end
66
74
 
67
75
  def to_s
@@ -134,5 +142,29 @@ module RBS
134
142
  def required_key?(name)
135
143
  _required_keys.include?(name)
136
144
  end
145
+
146
+ def local_location
147
+ loc = Location.new(buffer.detach, _start_pos, _end_pos)
148
+
149
+ each_optional_key do |key|
150
+ value = self[key]
151
+ if value
152
+ loc.add_optional_child(key, value._start_pos...value._end_pos)
153
+ else
154
+ loc.add_optional_child(key, nil)
155
+ end
156
+ end
157
+
158
+ each_required_key do |key|
159
+ value = self[key] or raise
160
+ loc.add_required_child(key, value._start_pos...value._end_pos)
161
+ end
162
+
163
+ loc #: self
164
+ end
165
+
166
+ def local_source
167
+ local_location.source
168
+ end
137
169
  end
138
170
  end
@@ -35,11 +35,6 @@ module RBS
35
35
  [buf, dirs, decls]
36
36
  end
37
37
 
38
- def self.parse_type_params(source, module_type_params: true)
39
- buf = buffer(source)
40
- _parse_type_params(buf, 0, buf.last_position, module_type_params)
41
- end
42
-
43
38
  def self.magic_comment(buf)
44
39
  start_pos = 0
45
40
 
@@ -76,7 +71,7 @@ module RBS
76
71
  def self.buffer(source)
77
72
  case source
78
73
  when String
79
- Buffer.new(content: source, name: "a.rbs")
74
+ Buffer.new(content: source, name: Pathname("a.rbs"))
80
75
  when Buffer
81
76
  source
82
77
  end
@@ -115,5 +110,15 @@ module RBS
115
110
  ).each_with_object({}) do |keyword, hash| #$ Hash[String, bot]
116
111
  hash[keyword] = _ = nil
117
112
  end
113
+
114
+ def self.parse_inline_leading_annotation(source, range, variables: [])
115
+ buf = buffer(source)
116
+ _parse_inline_leading_annotation(buf, range.begin || 0, range.end || buf.last_position, variables)
117
+ end
118
+
119
+ def self.parse_inline_trailing_annotation(source, range, variables: [])
120
+ buf = buffer(source)
121
+ _parse_inline_trailing_annotation(buf, range.begin || 0, range.end || buf.last_position, variables)
122
+ end
118
123
  end
119
124
  end
@@ -50,8 +50,8 @@ module RBS
50
50
  type_name_absolute = type_name.absolute!
51
51
  @mixin_decls_cache ||= {} #: Hash[TypeName, Array[AST::Members::Mixin]]
52
52
  @mixin_decls_cache.fetch(type_name_absolute) do
53
- @mixin_decls_cache[type_name_absolute] = @builder.env.class_decls[type_name_absolute].decls.flat_map do |d|
54
- d.decl.members.select { |m| m.kind_of?(AST::Members::Mixin) }
53
+ @mixin_decls_cache[type_name_absolute] = @builder.env.class_decls[type_name_absolute].each_decl.flat_map do |decl|
54
+ decl.members.select { |m| m.kind_of?(AST::Members::Mixin) }
55
55
  end
56
56
  end
57
57
  end
@@ -32,7 +32,7 @@ module RBS
32
32
  end
33
33
 
34
34
  environment.class_alias_decls.each do |name, entry|
35
- normalized_entry = environment.module_class_entry(name, normalized: true) or next
35
+ normalized_entry = environment.normalized_module_class_entry(name) or next
36
36
  constant = constant_of_module(name, normalized_entry)
37
37
 
38
38
  # Insert class/module aliases into `children_table` and `toplevel` table
@@ -176,7 +176,7 @@ module RBS
176
176
  end
177
177
 
178
178
  def constants_from_ancestors(module_name, constants:)
179
- entry = builder.env.module_class_entry(module_name, normalized: true) or raise
179
+ entry = builder.env.normalized_module_class_entry(module_name) or raise
180
180
 
181
181
  if entry.is_a?(Environment::ClassEntry) || entry.is_a?(Environment::ModuleEntry)
182
182
  constants.merge!(table.children(BuiltinNames::Object.name) || raise)