ruby-lsp 0.23.11 → 0.23.16

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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/exe/ruby-lsp-launcher +20 -11
  5. data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
  6. data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
  7. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +82 -116
  8. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +123 -169
  9. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
  10. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +92 -202
  11. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +116 -222
  12. data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
  13. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +18 -19
  14. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
  15. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +47 -61
  16. data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +17 -19
  17. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
  18. data/lib/ruby_indexer/test/class_variables_test.rb +14 -14
  19. data/lib/ruby_indexer/test/classes_and_modules_test.rb +65 -40
  20. data/lib/ruby_indexer/test/configuration_test.rb +48 -7
  21. data/lib/ruby_indexer/test/constant_test.rb +34 -34
  22. data/lib/ruby_indexer/test/enhancements_test.rb +1 -1
  23. data/lib/ruby_indexer/test/index_test.rb +139 -135
  24. data/lib/ruby_indexer/test/instance_variables_test.rb +37 -37
  25. data/lib/ruby_indexer/test/method_test.rb +143 -117
  26. data/lib/ruby_indexer/test/prefix_tree_test.rb +13 -13
  27. data/lib/ruby_indexer/test/rbs_indexer_test.rb +65 -71
  28. data/lib/ruby_indexer/test/test_case.rb +2 -2
  29. data/lib/ruby_indexer/test/uri_test.rb +15 -2
  30. data/lib/ruby_lsp/addon.rb +44 -71
  31. data/lib/ruby_lsp/base_server.rb +29 -32
  32. data/lib/ruby_lsp/client_capabilities.rb +10 -12
  33. data/lib/ruby_lsp/document.rb +39 -45
  34. data/lib/ruby_lsp/erb_document.rb +36 -40
  35. data/lib/ruby_lsp/global_state.rb +52 -57
  36. data/lib/ruby_lsp/internal.rb +2 -0
  37. data/lib/ruby_lsp/listeners/code_lens.rb +82 -89
  38. data/lib/ruby_lsp/listeners/completion.rb +60 -66
  39. data/lib/ruby_lsp/listeners/definition.rb +38 -52
  40. data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
  41. data/lib/ruby_lsp/listeners/document_link.rb +46 -63
  42. data/lib/ruby_lsp/listeners/document_symbol.rb +38 -52
  43. data/lib/ruby_lsp/listeners/folding_ranges.rb +40 -43
  44. data/lib/ruby_lsp/listeners/hover.rb +83 -102
  45. data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
  46. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +54 -56
  47. data/lib/ruby_lsp/listeners/signature_help.rb +11 -26
  48. data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
  49. data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
  50. data/lib/ruby_lsp/listeners/test_style.rb +160 -88
  51. data/lib/ruby_lsp/node_context.rb +12 -39
  52. data/lib/ruby_lsp/rbs_document.rb +8 -6
  53. data/lib/ruby_lsp/requests/code_action_resolve.rb +24 -25
  54. data/lib/ruby_lsp/requests/code_actions.rb +14 -26
  55. data/lib/ruby_lsp/requests/code_lens.rb +6 -17
  56. data/lib/ruby_lsp/requests/completion.rb +7 -20
  57. data/lib/ruby_lsp/requests/completion_resolve.rb +6 -6
  58. data/lib/ruby_lsp/requests/definition.rb +8 -17
  59. data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
  60. data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
  61. data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
  62. data/lib/ruby_lsp/requests/document_link.rb +6 -17
  63. data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
  64. data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
  65. data/lib/ruby_lsp/requests/formatting.rb +6 -9
  66. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
  67. data/lib/ruby_lsp/requests/hover.rb +10 -20
  68. data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
  69. data/lib/ruby_lsp/requests/on_type_formatting.rb +32 -40
  70. data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
  71. data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +5 -15
  72. data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
  73. data/lib/ruby_lsp/requests/references.rb +8 -37
  74. data/lib/ruby_lsp/requests/rename.rb +19 -42
  75. data/lib/ruby_lsp/requests/request.rb +7 -19
  76. data/lib/ruby_lsp/requests/selection_ranges.rb +6 -6
  77. data/lib/ruby_lsp/requests/semantic_highlighting.rb +16 -35
  78. data/lib/ruby_lsp/requests/show_syntax_tree.rb +7 -8
  79. data/lib/ruby_lsp/requests/signature_help.rb +8 -26
  80. data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
  81. data/lib/ruby_lsp/requests/support/common.rb +16 -51
  82. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
  83. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +11 -14
  84. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
  85. data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
  86. data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
  87. data/lib/ruby_lsp/requests/support/source_uri.rb +20 -32
  88. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
  89. data/lib/ruby_lsp/requests/support/test_item.rb +10 -14
  90. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
  91. data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
  92. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
  93. data/lib/ruby_lsp/response_builders/document_symbol.rb +13 -18
  94. data/lib/ruby_lsp/response_builders/hover.rb +11 -14
  95. data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
  96. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +60 -88
  97. data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
  98. data/lib/ruby_lsp/response_builders/test_collection.rb +6 -10
  99. data/lib/ruby_lsp/ruby_document.rb +24 -62
  100. data/lib/ruby_lsp/scope.rb +7 -11
  101. data/lib/ruby_lsp/scripts/compose_bundle.rb +6 -4
  102. data/lib/ruby_lsp/server.rb +147 -79
  103. data/lib/ruby_lsp/setup_bundler.rb +65 -60
  104. data/lib/ruby_lsp/static_docs.rb +11 -7
  105. data/lib/ruby_lsp/store.rb +24 -42
  106. data/lib/ruby_lsp/test_helper.rb +2 -12
  107. data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +164 -0
  108. data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +105 -0
  109. data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +94 -0
  110. data/lib/ruby_lsp/type_inferrer.rb +13 -14
  111. data/lib/ruby_lsp/utils.rb +49 -83
  112. metadata +9 -3
@@ -8,30 +8,30 @@ module RubyIndexer
8
8
 
9
9
  abstract!
10
10
 
11
- @enhancements = T.let([], T::Array[T::Class[Enhancement]])
11
+ @enhancements = [] #: Array[Class[Enhancement]]
12
12
 
13
13
  class << self
14
14
  extend T::Sig
15
15
 
16
- sig { params(child: T::Class[Enhancement]).void }
16
+ #: (Class[Enhancement] child) -> void
17
17
  def inherited(child)
18
18
  @enhancements << child
19
19
  super
20
20
  end
21
21
 
22
- sig { params(listener: DeclarationListener).returns(T::Array[Enhancement]) }
22
+ #: (DeclarationListener listener) -> Array[Enhancement]
23
23
  def all(listener)
24
24
  @enhancements.map { |enhancement| enhancement.new(listener) }
25
25
  end
26
26
 
27
27
  # Only available for testing purposes
28
- sig { void }
28
+ #: -> void
29
29
  def clear
30
30
  @enhancements.clear
31
31
  end
32
32
  end
33
33
 
34
- sig { params(listener: DeclarationListener).void }
34
+ #: (DeclarationListener listener) -> void
35
35
  def initialize(listener)
36
36
  @listener = listener
37
37
  end
@@ -39,10 +39,12 @@ module RubyIndexer
39
39
  # The `on_extend` indexing enhancement is invoked whenever an extend is encountered in the code. It can be used to
40
40
  # register for an included callback, similar to what `ActiveSupport::Concern` does in order to auto-extend the
41
41
  # `ClassMethods` modules
42
- sig { overridable.params(node: Prism::CallNode).void }
42
+ # @overridable
43
+ #: (Prism::CallNode node) -> void
43
44
  def on_call_node_enter(node); end # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
44
45
 
45
- sig { overridable.params(node: Prism::CallNode).void }
46
+ # @overridable
47
+ #: (Prism::CallNode node) -> void
46
48
  def on_call_node_leave(node); end # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
47
49
  end
48
50
  end
@@ -11,68 +11,61 @@ module RubyIndexer
11
11
  end
12
12
  end
13
13
 
14
- extend T::Sig
15
-
16
- sig { returns(String) }
14
+ #: String
17
15
  attr_reader :name
18
16
 
19
- sig { returns(URI::Generic) }
17
+ #: URI::Generic
20
18
  attr_reader :uri
21
19
 
22
- sig { returns(RubyIndexer::Location) }
20
+ #: RubyIndexer::Location
23
21
  attr_reader :location
24
22
 
25
23
  alias_method :name_location, :location
26
24
 
27
- sig { returns(Visibility) }
25
+ #: Visibility
28
26
  attr_accessor :visibility
29
27
 
30
- sig do
31
- params(
32
- name: String,
33
- uri: URI::Generic,
34
- location: Location,
35
- comments: T.nilable(String),
36
- ).void
37
- end
28
+ #: (String name, URI::Generic uri, Location location, String? comments) -> void
38
29
  def initialize(name, uri, location, comments)
39
30
  @name = name
40
31
  @uri = uri
41
32
  @comments = comments
42
- @visibility = T.let(Visibility::PUBLIC, Visibility)
33
+ @visibility = Visibility::PUBLIC #: Visibility
43
34
  @location = location
44
35
  end
45
36
 
46
- sig { returns(T::Boolean) }
37
+ #: -> bool
47
38
  def public?
48
39
  visibility == Visibility::PUBLIC
49
40
  end
50
41
 
51
- sig { returns(T::Boolean) }
42
+ #: -> bool
52
43
  def protected?
53
44
  visibility == Visibility::PROTECTED
54
45
  end
55
46
 
56
- sig { returns(T::Boolean) }
47
+ #: -> bool
57
48
  def private?
58
49
  visibility == Visibility::PRIVATE
59
50
  end
60
51
 
61
- sig { returns(String) }
52
+ #: -> String
62
53
  def file_name
63
54
  if @uri.scheme == "untitled"
64
- T.must(@uri.opaque)
55
+ @uri.opaque #: as !nil
65
56
  else
66
- File.basename(T.must(file_path))
57
+ File.basename(
58
+ file_path, #: as !nil
59
+ )
67
60
  end
68
61
  end
69
62
 
70
- sig { returns(T.nilable(String)) }
63
+ #: -> String?
71
64
  def file_path
72
65
  @uri.full_path
73
66
  end
74
67
 
75
- sig { returns(String) }
68
+ #: -> String
76
69
  def comments
77
70
  @comments ||= begin
78
71
  # Parse only the comments based on the file path, which is much faster than parsing the entire file
@@ -119,10 +112,10 @@ module RubyIndexer
119
112
 
120
113
  abstract!
121
114
 
122
- sig { returns(String) }
115
+ #: String
123
116
  attr_reader :module_name
124
117
 
125
- sig { params(module_name: String).void }
118
+ #: (String module_name) -> void
126
119
  def initialize(module_name)
127
120
  @module_name = module_name
128
121
  end
@@ -137,24 +130,16 @@ module RubyIndexer
137
130
 
138
131
  abstract!
139
132
 
140
- sig { returns(T::Array[String]) }
133
+ #: Array[String]
141
134
  attr_reader :nesting
142
135
 
143
136
  # Returns the location of the constant name, excluding the parent class or the body
144
- sig { returns(Location) }
137
+ #: Location
145
138
  attr_reader :name_location
146
139
 
147
- sig do
148
- params(
149
- nesting: T::Array[String],
150
- uri: URI::Generic,
151
- location: Location,
152
- name_location: Location,
153
- comments: T.nilable(String),
154
- ).void
155
- end
140
+ #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
156
141
  def initialize(nesting, uri, location, name_location, comments)
157
- @name = T.let(nesting.join("::"), String)
142
+ @name = nesting.join("::") #: String
158
143
  # The original nesting where this namespace was discovered
159
144
  @nesting = nesting
160
145
 
@@ -163,7 +148,7 @@ module RubyIndexer
163
148
  @name_location = name_location
164
149
  end
165
150
 
166
- sig { returns(T::Array[String]) }
151
+ #: -> Array[String]
167
152
  def mixin_operation_module_names
168
153
  mixin_operations.map(&:module_name)
169
154
  end
@@ -171,12 +156,12 @@ module RubyIndexer
171
156
  # Stores all explicit prepend, include and extend operations in the exact order they were discovered in the source
172
157
  # code. Maintaining the order is essential to linearize ancestors the right way when a module is both included
173
158
  # and prepended
174
- sig { returns(T::Array[ModuleOperation]) }
159
+ #: -> Array[ModuleOperation]
175
160
  def mixin_operations
176
- @mixin_operations ||= T.let([], T.nilable(T::Array[ModuleOperation]))
161
+ @mixin_operations ||= [] #: Array[ModuleOperation]?
177
162
  end
178
163
 
179
- sig { returns(Integer) }
164
+ #: -> Integer
180
165
  def ancestor_hash
181
166
  mixin_operation_module_names.hash
182
167
  end
@@ -186,44 +171,26 @@ module RubyIndexer
186
171
  end
187
172
 
188
173
  class Class < Namespace
189
- extend T::Sig
190
-
191
174
  # The unresolved name of the parent class. This may return `nil`, which indicates the lack of an explicit parent
192
175
  # and therefore ::Object is the correct parent class
193
- sig { returns(T.nilable(String)) }
176
+ #: String?
194
177
  attr_reader :parent_class
195
178
 
196
- sig do
197
- params(
198
- nesting: T::Array[String],
199
- uri: URI::Generic,
200
- location: Location,
201
- name_location: Location,
202
- comments: T.nilable(String),
203
- parent_class: T.nilable(String),
204
- ).void
205
- end
179
+ #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments, String? parent_class) -> void
206
180
  def initialize(nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
207
181
  super(nesting, uri, location, name_location, comments)
208
182
  @parent_class = parent_class
209
183
  end
210
184
 
211
- sig { override.returns(Integer) }
185
+ # @override
186
+ #: -> Integer
212
187
  def ancestor_hash
213
188
  [mixin_operation_module_names, @parent_class].hash
214
189
  end
215
190
  end
216
191
 
217
192
  class SingletonClass < Class
218
- extend T::Sig
219
-
220
- sig do
221
- params(
222
- location: Location,
223
- name_location: Location,
224
- comments: T.nilable(String),
225
- ).void
226
- end
193
+ #: (Location location, Location name_location, String? comments) -> void
227
194
  def update_singleton_information(location, name_location, comments)
228
195
  @location = location
229
196
  @name_location = name_location
@@ -241,13 +208,13 @@ module RubyIndexer
241
208
  abstract!
242
209
 
243
210
  # Name includes just the name of the parameter, excluding symbols like splats
244
- sig { returns(Symbol) }
211
+ #: Symbol
245
212
  attr_reader :name
246
213
 
247
214
  # Decorated name is the parameter name including the splat or block prefix, e.g.: `*foo`, `**foo` or `&block`
248
215
  alias_method :decorated_name, :name
249
216
 
250
- sig { params(name: Symbol).void }
217
+ #: (name: Symbol) -> void
251
218
  def initialize(name:)
252
219
  @name = name
253
220
  end
@@ -259,7 +226,8 @@ module RubyIndexer
259
226
 
260
227
  # An optional method parameter, e.g. `def foo(a = 123)`
261
228
  class OptionalParameter < Parameter
262
- sig { override.returns(Symbol) }
229
+ # @override
230
+ #: -> Symbol
263
231
  def decorated_name
264
232
  :"#{@name} = <default>"
265
233
  end
@@ -267,7 +235,8 @@ module RubyIndexer
267
235
 
268
236
  # An required keyword method parameter, e.g. `def foo(a:)`
269
237
  class KeywordParameter < Parameter
270
- sig { override.returns(Symbol) }
238
+ # @override
239
+ #: -> Symbol
271
240
  def decorated_name
272
241
  :"#{@name}:"
273
242
  end
@@ -275,7 +244,8 @@ module RubyIndexer
275
244
 
276
245
  # An optional keyword method parameter, e.g. `def foo(a: 123)`
277
246
  class OptionalKeywordParameter < Parameter
278
- sig { override.returns(Symbol) }
247
+ # @override
248
+ #: -> Symbol
279
249
  def decorated_name
280
250
  :"#{@name}: <default>"
281
251
  end
@@ -283,9 +253,10 @@ module RubyIndexer
283
253
 
284
254
  # A rest method parameter, e.g. `def foo(*a)`
285
255
  class RestParameter < Parameter
286
- DEFAULT_NAME = T.let(:"<anonymous splat>", Symbol)
256
+ DEFAULT_NAME = :"<anonymous splat>" #: Symbol
287
257
 
288
- sig { override.returns(Symbol) }
258
+ # @override
259
+ #: -> Symbol
289
260
  def decorated_name
290
261
  :"*#{@name}"
291
262
  end
@@ -293,9 +264,10 @@ module RubyIndexer
293
264
 
294
265
  # A keyword rest method parameter, e.g. `def foo(**a)`
295
266
  class KeywordRestParameter < Parameter
296
- DEFAULT_NAME = T.let(:"<anonymous keyword splat>", Symbol)
267
+ DEFAULT_NAME = :"<anonymous keyword splat>" #: Symbol
297
268
 
298
- sig { override.returns(Symbol) }
269
+ # @override
270
+ #: -> Symbol
299
271
  def decorated_name
300
272
  :"**#{@name}"
301
273
  end
@@ -303,17 +275,17 @@ module RubyIndexer
303
275
 
304
276
  # A block method parameter, e.g. `def foo(&block)`
305
277
  class BlockParameter < Parameter
306
- DEFAULT_NAME = T.let(:"<anonymous block>", Symbol)
278
+ DEFAULT_NAME = :"<anonymous block>" #: Symbol
307
279
 
308
280
  class << self
309
- extend T::Sig
310
- sig { returns(BlockParameter) }
281
+ #: -> BlockParameter
311
282
  def anonymous
312
283
  new(name: DEFAULT_NAME)
313
284
  end
314
285
  end
315
286
 
316
- sig { override.returns(Symbol) }
287
+ # @override
288
+ #: -> Symbol
317
289
  def decorated_name
318
290
  :"&#{@name}"
319
291
  end
@@ -321,9 +293,7 @@ module RubyIndexer
321
293
 
322
294
  # A forwarding method parameter, e.g. `def foo(...)`
323
295
  class ForwardingParameter < Parameter
324
- extend T::Sig
325
-
326
- sig { void }
296
+ #: -> void
327
297
  def initialize
328
298
  # You can't name a forwarding parameter, it's always called `...`
329
299
  super(name: :"...")
@@ -336,19 +306,10 @@ module RubyIndexer
336
306
 
337
307
  abstract!
338
308
 
339
- sig { returns(T.nilable(Entry::Namespace)) }
309
+ #: Entry::Namespace?
340
310
  attr_reader :owner
341
311
 
342
- sig do
343
- params(
344
- name: String,
345
- uri: URI::Generic,
346
- location: Location,
347
- comments: T.nilable(String),
348
- visibility: Visibility,
349
- owner: T.nilable(Entry::Namespace),
350
- ).void
351
- end
312
+ #: (String name, URI::Generic uri, Location location, String? comments, Visibility visibility, Entry::Namespace? owner) -> void
352
313
  def initialize(name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
353
314
  super(name, uri, location, comments)
354
315
  @visibility = visibility
@@ -358,7 +319,7 @@ module RubyIndexer
358
319
  sig { abstract.returns(T::Array[Entry::Signature]) }
359
320
  def signatures; end
360
321
 
361
- sig { returns(String) }
322
+ #: -> String
362
323
  def decorated_parameters
363
324
  first_signature = signatures.first
364
325
  return "()" unless first_signature
@@ -366,7 +327,7 @@ module RubyIndexer
366
327
  "(#{first_signature.format})"
367
328
  end
368
329
 
369
- sig { returns(String) }
330
+ #: -> String
370
331
  def formatted_signatures
371
332
  overloads_count = signatures.size
372
333
  case overloads_count
@@ -381,43 +342,26 @@ module RubyIndexer
381
342
  end
382
343
 
383
344
  class Accessor < Member
384
- extend T::Sig
385
-
386
- sig { override.returns(T::Array[Signature]) }
345
+ # @override
346
+ #: -> Array[Signature]
387
347
  def signatures
388
- @signatures ||= T.let(
389
- begin
390
- params = []
391
- params << RequiredParameter.new(name: name.delete_suffix("=").to_sym) if name.end_with?("=")
392
- [Entry::Signature.new(params)]
393
- end,
394
- T.nilable(T::Array[Signature]),
395
- )
348
+ @signatures ||= begin
349
+ params = []
350
+ params << RequiredParameter.new(name: name.delete_suffix("=").to_sym) if name.end_with?("=")
351
+ [Entry::Signature.new(params)]
352
+ end #: Array[Signature]?
396
353
  end
397
354
  end
398
355
 
399
356
  class Method < Member
400
- extend T::Sig
401
-
402
- sig { override.returns(T::Array[Signature]) }
357
+ #: Array[Signature]
403
358
  attr_reader :signatures
404
359
 
405
360
  # Returns the location of the method name, excluding parameters or the body
406
- sig { returns(Location) }
361
+ #: Location
407
362
  attr_reader :name_location
408
363
 
409
- sig do
410
- params(
411
- name: String,
412
- uri: URI::Generic,
413
- location: Location,
414
- name_location: Location,
415
- comments: T.nilable(String),
416
- signatures: T::Array[Signature],
417
- visibility: Visibility,
418
- owner: T.nilable(Entry::Namespace),
419
- ).void
420
- end
364
+ #: (String name, URI::Generic uri, Location location, Location name_location, String? comments, Array[Signature] signatures, Visibility visibility, Entry::Namespace? owner) -> void
421
365
  def initialize(name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
422
366
  super(name, uri, location, comments, visibility, owner)
423
367
  @signatures = signatures
@@ -436,24 +380,13 @@ module RubyIndexer
436
380
  # target in [rdoc-ref:Index#resolve]. If the right hand side contains a constant that doesn't exist, then it's not
437
381
  # possible to resolve the alias and it will remain an UnresolvedAlias until the right hand side constant exists
438
382
  class UnresolvedConstantAlias < Entry
439
- extend T::Sig
440
-
441
- sig { returns(String) }
383
+ #: String
442
384
  attr_reader :target
443
385
 
444
- sig { returns(T::Array[String]) }
386
+ #: Array[String]
445
387
  attr_reader :nesting
446
388
 
447
- sig do
448
- params(
449
- target: String,
450
- nesting: T::Array[String],
451
- name: String,
452
- uri: URI::Generic,
453
- location: Location,
454
- comments: T.nilable(String),
455
- ).void
456
- end
389
+ #: (String target, Array[String] nesting, String name, URI::Generic uri, Location location, String? comments) -> void
457
390
  def initialize(target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
458
391
  super(name, uri, location, comments)
459
392
 
@@ -464,12 +397,10 @@ module RubyIndexer
464
397
 
465
398
  # Alias represents a resolved alias, which points to an existing constant target
466
399
  class ConstantAlias < Entry
467
- extend T::Sig
468
-
469
- sig { returns(String) }
400
+ #: String
470
401
  attr_reader :target
471
402
 
472
- sig { params(target: String, unresolved_alias: UnresolvedConstantAlias).void }
403
+ #: (String target, UnresolvedConstantAlias unresolved_alias) -> void
473
404
  def initialize(target, unresolved_alias)
474
405
  super(
475
406
  unresolved_alias.name,
@@ -488,18 +419,10 @@ module RubyIndexer
488
419
 
489
420
  # Represents a class variable e.g.: @@a = 1
490
421
  class ClassVariable < Entry
491
- sig { returns(T.nilable(Entry::Namespace)) }
422
+ #: Entry::Namespace?
492
423
  attr_reader :owner
493
424
 
494
- sig do
495
- params(
496
- name: String,
497
- uri: URI::Generic,
498
- location: Location,
499
- comments: T.nilable(String),
500
- owner: T.nilable(Entry::Namespace),
501
- ).void
502
- end
425
+ #: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
503
426
  def initialize(name, uri, location, comments, owner)
504
427
  super(name, uri, location, comments)
505
428
  @owner = owner
@@ -508,18 +431,10 @@ module RubyIndexer
508
431
 
509
432
  # Represents an instance variable e.g.: @a = 1
510
433
  class InstanceVariable < Entry
511
- sig { returns(T.nilable(Entry::Namespace)) }
434
+ #: Entry::Namespace?
512
435
  attr_reader :owner
513
436
 
514
- sig do
515
- params(
516
- name: String,
517
- uri: URI::Generic,
518
- location: Location,
519
- comments: T.nilable(String),
520
- owner: T.nilable(Entry::Namespace),
521
- ).void
522
- end
437
+ #: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
523
438
  def initialize(name, uri, location, comments, owner)
524
439
  super(name, uri, location, comments)
525
440
  @owner = owner
@@ -530,24 +445,13 @@ module RubyIndexer
530
445
  # example, if we have `alias a b`, we create an unresolved alias for `a` because we aren't sure immediate what `b`
531
446
  # is referring to
532
447
  class UnresolvedMethodAlias < Entry
533
- extend T::Sig
534
-
535
- sig { returns(String) }
448
+ #: String
536
449
  attr_reader :new_name, :old_name
537
450
 
538
- sig { returns(T.nilable(Entry::Namespace)) }
451
+ #: Entry::Namespace?
539
452
  attr_reader :owner
540
453
 
541
- sig do
542
- params(
543
- new_name: String,
544
- old_name: String,
545
- owner: T.nilable(Entry::Namespace),
546
- uri: URI::Generic,
547
- location: Location,
548
- comments: T.nilable(String),
549
- ).void
550
- end
454
+ #: (String new_name, String old_name, Entry::Namespace? owner, URI::Generic uri, Location location, String? comments) -> void
551
455
  def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
552
456
  super(new_name, uri, location, comments)
553
457
 
@@ -559,17 +463,13 @@ module RubyIndexer
559
463
 
560
464
  # A method alias is a resolved alias entry that points to the exact method target it refers to
561
465
  class MethodAlias < Entry
562
- extend T::Sig
563
-
564
- sig { returns(T.any(Member, MethodAlias)) }
466
+ #: (Member | MethodAlias)
565
467
  attr_reader :target
566
468
 
567
- sig { returns(T.nilable(Entry::Namespace)) }
469
+ #: Entry::Namespace?
568
470
  attr_reader :owner
569
471
 
570
- sig do
571
- params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias).void
572
- end
472
+ #: ((Member | MethodAlias) target, UnresolvedMethodAlias unresolved_alias) -> void
573
473
  def initialize(target, unresolved_alias)
574
474
  full_comments = +"Alias for #{target.name}\n"
575
475
  full_comments << "#{unresolved_alias.comments}\n"
@@ -583,20 +483,20 @@ module RubyIndexer
583
483
  )
584
484
 
585
485
  @target = target
586
- @owner = T.let(unresolved_alias.owner, T.nilable(Entry::Namespace))
486
+ @owner = unresolved_alias.owner #: Entry::Namespace?
587
487
  end
588
488
 
589
- sig { returns(String) }
489
+ #: -> String
590
490
  def decorated_parameters
591
491
  @target.decorated_parameters
592
492
  end
593
493
 
594
- sig { returns(String) }
494
+ #: -> String
595
495
  def formatted_signatures
596
496
  @target.formatted_signatures
597
497
  end
598
498
 
599
- sig { returns(T::Array[Signature]) }
499
+ #: -> Array[Signature]
600
500
  def signatures
601
501
  @target.signatures
602
502
  end
@@ -606,18 +506,16 @@ module RubyIndexer
606
506
  # However RBS can represent the concept of method overloading, with different return types based on the arguments
607
507
  # passed, so we need to store all the signatures.
608
508
  class Signature
609
- extend T::Sig
610
-
611
- sig { returns(T::Array[Parameter]) }
509
+ #: Array[Parameter]
612
510
  attr_reader :parameters
613
511
 
614
- sig { params(parameters: T::Array[Parameter]).void }
512
+ #: (Array[Parameter] parameters) -> void
615
513
  def initialize(parameters)
616
514
  @parameters = parameters
617
515
  end
618
516
 
619
517
  # Returns a string with the decorated names of the parameters of this member. E.g.: `(a, b = 1, c: 2)`
620
- sig { returns(String) }
518
+ #: -> String
621
519
  def format
622
520
  @parameters.map(&:decorated_name).join(", ")
623
521
  end
@@ -637,13 +535,13 @@ module RubyIndexer
637
535
  # foo(1)
638
536
  # foo(1, 2)
639
537
  # ```
640
- sig { params(arguments: T::Array[Prism::Node]).returns(T::Boolean) }
538
+ #: (Array[Prism::Node] arguments) -> bool
641
539
  def matches?(arguments)
642
540
  min_pos = 0
643
- max_pos = T.let(0, T.any(Integer, Float))
541
+ max_pos = 0 #: (Integer | Float)
644
542
  names = []
645
- has_forward = T.let(false, T::Boolean)
646
- has_keyword_rest = T.let(false, T::Boolean)
543
+ has_forward = false #: bool
544
+ has_keyword_rest = false #: bool
647
545
 
648
546
  @parameters.each do |param|
649
547
  case param
@@ -688,15 +586,7 @@ module RubyIndexer
688
586
  )
689
587
  end
690
588
 
691
- sig do
692
- params(
693
- positional_args: T::Array[Prism::Node],
694
- forwarding_arguments: T::Array[Prism::Node],
695
- keyword_args: T.nilable(T::Array[Prism::Node]),
696
- min_pos: Integer,
697
- max_pos: T.any(Integer, Float),
698
- ).returns(T::Boolean)
699
- end
589
+ #: (Array[Prism::Node] positional_args, Array[Prism::Node] forwarding_arguments, Array[Prism::Node]? keyword_args, Integer min_pos, (Integer | Float) max_pos) -> bool
700
590
  def positional_arguments_match?(positional_args, forwarding_arguments, keyword_args, min_pos, max_pos)
701
591
  # If the method accepts at least one positional argument and a splat has been passed
702
592
  (min_pos > 0 && positional_args.any? { |arg| arg.is_a?(Prism::SplatNode) }) ||
@@ -709,7 +599,7 @@ module RubyIndexer
709
599
  (min_pos == 0 && positional_args.empty?)
710
600
  end
711
601
 
712
- sig { params(args: T.nilable(T::Array[Prism::Node]), names: T::Array[Symbol]).returns(T::Boolean) }
602
+ #: (Array[Prism::Node]? args, Array[Symbol] names) -> bool
713
603
  def keyword_arguments_match?(args, names)
714
604
  return true unless args
715
605
  return true if args.any? { |arg| arg.is_a?(Prism::AssocSplatNode) }