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