ruby-lsp 0.23.11 → 0.23.17

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 +134 -183
  9. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -10
  10. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +97 -217
  11. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +139 -281
  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 +23 -55
  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 +7 -11
  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 +146 -135
  24. data/lib/ruby_indexer/test/instance_variables_test.rb +37 -37
  25. data/lib/ruby_indexer/test/method_test.rb +149 -123
  26. data/lib/ruby_indexer/test/prefix_tree_test.rb +13 -13
  27. data/lib/ruby_indexer/test/rbs_indexer_test.rb +68 -73
  28. data/lib/ruby_indexer/test/test_case.rb +9 -3
  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 +40 -54
  34. data/lib/ruby_lsp/erb_document.rb +37 -41
  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 +67 -73
  39. data/lib/ruby_lsp/listeners/definition.rb +44 -58
  40. data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
  41. data/lib/ruby_lsp/listeners/document_link.rb +50 -70
  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 +92 -110
  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 +12 -27
  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 +167 -90
  51. data/lib/ruby_lsp/node_context.rb +12 -39
  52. data/lib/ruby_lsp/rbs_document.rb +9 -7
  53. data/lib/ruby_lsp/requests/code_action_resolve.rb +63 -59
  54. data/lib/ruby_lsp/requests/code_actions.rb +14 -26
  55. data/lib/ruby_lsp/requests/code_lens.rb +20 -19
  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 +7 -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 +85 -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 +9 -53
  74. data/lib/ruby_lsp/requests/rename.rb +20 -46
  75. data/lib/ruby_lsp/requests/request.rb +8 -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 +15 -55
  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 +16 -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 +14 -19
  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 +43 -10
  99. data/lib/ruby_lsp/ruby_document.rb +24 -92
  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 +182 -99
  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 +29 -47
  106. data/lib/ruby_lsp/test_helper.rb +2 -12
  107. data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +191 -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 +92 -83
  112. metadata +9 -3
@@ -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
@@ -114,15 +99,14 @@ module RubyIndexer
114
99
  end
115
100
 
116
101
  class ModuleOperation
117
- extend T::Sig
118
102
  extend T::Helpers
119
103
 
120
104
  abstract!
121
105
 
122
- sig { returns(String) }
106
+ #: String
123
107
  attr_reader :module_name
124
108
 
125
- sig { params(module_name: String).void }
109
+ #: (String module_name) -> void
126
110
  def initialize(module_name)
127
111
  @module_name = module_name
128
112
  end
@@ -132,29 +116,20 @@ module RubyIndexer
132
116
  class Prepend < ModuleOperation; end
133
117
 
134
118
  class Namespace < Entry
135
- extend T::Sig
136
119
  extend T::Helpers
137
120
 
138
121
  abstract!
139
122
 
140
- sig { returns(T::Array[String]) }
123
+ #: Array[String]
141
124
  attr_reader :nesting
142
125
 
143
126
  # Returns the location of the constant name, excluding the parent class or the body
144
- sig { returns(Location) }
127
+ #: Location
145
128
  attr_reader :name_location
146
129
 
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
130
+ #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
156
131
  def initialize(nesting, uri, location, name_location, comments)
157
- @name = T.let(nesting.join("::"), String)
132
+ @name = nesting.join("::") #: String
158
133
  # The original nesting where this namespace was discovered
159
134
  @nesting = nesting
160
135
 
@@ -163,7 +138,7 @@ module RubyIndexer
163
138
  @name_location = name_location
164
139
  end
165
140
 
166
- sig { returns(T::Array[String]) }
141
+ #: -> Array[String]
167
142
  def mixin_operation_module_names
168
143
  mixin_operations.map(&:module_name)
169
144
  end
@@ -171,12 +146,12 @@ module RubyIndexer
171
146
  # Stores all explicit prepend, include and extend operations in the exact order they were discovered in the source
172
147
  # code. Maintaining the order is essential to linearize ancestors the right way when a module is both included
173
148
  # and prepended
174
- sig { returns(T::Array[ModuleOperation]) }
149
+ #: -> Array[ModuleOperation]
175
150
  def mixin_operations
176
- @mixin_operations ||= T.let([], T.nilable(T::Array[ModuleOperation]))
151
+ @mixin_operations ||= [] #: Array[ModuleOperation]?
177
152
  end
178
153
 
179
- sig { returns(Integer) }
154
+ #: -> Integer
180
155
  def ancestor_hash
181
156
  mixin_operation_module_names.hash
182
157
  end
@@ -186,44 +161,26 @@ module RubyIndexer
186
161
  end
187
162
 
188
163
  class Class < Namespace
189
- extend T::Sig
190
-
191
164
  # The unresolved name of the parent class. This may return `nil`, which indicates the lack of an explicit parent
192
165
  # and therefore ::Object is the correct parent class
193
- sig { returns(T.nilable(String)) }
166
+ #: String?
194
167
  attr_reader :parent_class
195
168
 
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
169
+ #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments, String? parent_class) -> void
206
170
  def initialize(nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
207
171
  super(nesting, uri, location, name_location, comments)
208
172
  @parent_class = parent_class
209
173
  end
210
174
 
211
- sig { override.returns(Integer) }
175
+ # @override
176
+ #: -> Integer
212
177
  def ancestor_hash
213
178
  [mixin_operation_module_names, @parent_class].hash
214
179
  end
215
180
  end
216
181
 
217
182
  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
183
+ #: (Location location, Location name_location, String? comments) -> void
227
184
  def update_singleton_information(location, name_location, comments)
228
185
  @location = location
229
186
  @name_location = name_location
@@ -236,18 +193,17 @@ module RubyIndexer
236
193
 
237
194
  class Parameter
238
195
  extend T::Helpers
239
- extend T::Sig
240
196
 
241
197
  abstract!
242
198
 
243
199
  # Name includes just the name of the parameter, excluding symbols like splats
244
- sig { returns(Symbol) }
200
+ #: Symbol
245
201
  attr_reader :name
246
202
 
247
203
  # Decorated name is the parameter name including the splat or block prefix, e.g.: `*foo`, `**foo` or `&block`
248
204
  alias_method :decorated_name, :name
249
205
 
250
- sig { params(name: Symbol).void }
206
+ #: (name: Symbol) -> void
251
207
  def initialize(name:)
252
208
  @name = name
253
209
  end
@@ -259,7 +215,8 @@ module RubyIndexer
259
215
 
260
216
  # An optional method parameter, e.g. `def foo(a = 123)`
261
217
  class OptionalParameter < Parameter
262
- sig { override.returns(Symbol) }
218
+ # @override
219
+ #: -> Symbol
263
220
  def decorated_name
264
221
  :"#{@name} = <default>"
265
222
  end
@@ -267,7 +224,8 @@ module RubyIndexer
267
224
 
268
225
  # An required keyword method parameter, e.g. `def foo(a:)`
269
226
  class KeywordParameter < Parameter
270
- sig { override.returns(Symbol) }
227
+ # @override
228
+ #: -> Symbol
271
229
  def decorated_name
272
230
  :"#{@name}:"
273
231
  end
@@ -275,7 +233,8 @@ module RubyIndexer
275
233
 
276
234
  # An optional keyword method parameter, e.g. `def foo(a: 123)`
277
235
  class OptionalKeywordParameter < Parameter
278
- sig { override.returns(Symbol) }
236
+ # @override
237
+ #: -> Symbol
279
238
  def decorated_name
280
239
  :"#{@name}: <default>"
281
240
  end
@@ -283,9 +242,10 @@ module RubyIndexer
283
242
 
284
243
  # A rest method parameter, e.g. `def foo(*a)`
285
244
  class RestParameter < Parameter
286
- DEFAULT_NAME = T.let(:"<anonymous splat>", Symbol)
245
+ DEFAULT_NAME = :"<anonymous splat>" #: Symbol
287
246
 
288
- sig { override.returns(Symbol) }
247
+ # @override
248
+ #: -> Symbol
289
249
  def decorated_name
290
250
  :"*#{@name}"
291
251
  end
@@ -293,9 +253,10 @@ module RubyIndexer
293
253
 
294
254
  # A keyword rest method parameter, e.g. `def foo(**a)`
295
255
  class KeywordRestParameter < Parameter
296
- DEFAULT_NAME = T.let(:"<anonymous keyword splat>", Symbol)
256
+ DEFAULT_NAME = :"<anonymous keyword splat>" #: Symbol
297
257
 
298
- sig { override.returns(Symbol) }
258
+ # @override
259
+ #: -> Symbol
299
260
  def decorated_name
300
261
  :"**#{@name}"
301
262
  end
@@ -303,17 +264,17 @@ module RubyIndexer
303
264
 
304
265
  # A block method parameter, e.g. `def foo(&block)`
305
266
  class BlockParameter < Parameter
306
- DEFAULT_NAME = T.let(:"<anonymous block>", Symbol)
267
+ DEFAULT_NAME = :"<anonymous block>" #: Symbol
307
268
 
308
269
  class << self
309
- extend T::Sig
310
- sig { returns(BlockParameter) }
270
+ #: -> BlockParameter
311
271
  def anonymous
312
272
  new(name: DEFAULT_NAME)
313
273
  end
314
274
  end
315
275
 
316
- sig { override.returns(Symbol) }
276
+ # @override
277
+ #: -> Symbol
317
278
  def decorated_name
318
279
  :"&#{@name}"
319
280
  end
@@ -321,9 +282,7 @@ module RubyIndexer
321
282
 
322
283
  # A forwarding method parameter, e.g. `def foo(...)`
323
284
  class ForwardingParameter < Parameter
324
- extend T::Sig
325
-
326
- sig { void }
285
+ #: -> void
327
286
  def initialize
328
287
  # You can't name a forwarding parameter, it's always called `...`
329
288
  super(name: :"...")
@@ -336,19 +295,10 @@ module RubyIndexer
336
295
 
337
296
  abstract!
338
297
 
339
- sig { returns(T.nilable(Entry::Namespace)) }
298
+ #: Entry::Namespace?
340
299
  attr_reader :owner
341
300
 
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
301
+ #: (String name, URI::Generic uri, Location location, String? comments, Symbol visibility, Entry::Namespace? owner) -> void
352
302
  def initialize(name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
353
303
  super(name, uri, location, comments)
354
304
  @visibility = visibility
@@ -358,7 +308,7 @@ module RubyIndexer
358
308
  sig { abstract.returns(T::Array[Entry::Signature]) }
359
309
  def signatures; end
360
310
 
361
- sig { returns(String) }
311
+ #: -> String
362
312
  def decorated_parameters
363
313
  first_signature = signatures.first
364
314
  return "()" unless first_signature
@@ -366,7 +316,7 @@ module RubyIndexer
366
316
  "(#{first_signature.format})"
367
317
  end
368
318
 
369
- sig { returns(String) }
319
+ #: -> String
370
320
  def formatted_signatures
371
321
  overloads_count = signatures.size
372
322
  case overloads_count
@@ -381,43 +331,26 @@ module RubyIndexer
381
331
  end
382
332
 
383
333
  class Accessor < Member
384
- extend T::Sig
385
-
386
- sig { override.returns(T::Array[Signature]) }
334
+ # @override
335
+ #: -> Array[Signature]
387
336
  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
- )
337
+ @signatures ||= begin
338
+ params = []
339
+ params << RequiredParameter.new(name: name.delete_suffix("=").to_sym) if name.end_with?("=")
340
+ [Entry::Signature.new(params)]
341
+ end #: Array[Signature]?
396
342
  end
397
343
  end
398
344
 
399
345
  class Method < Member
400
- extend T::Sig
401
-
402
- sig { override.returns(T::Array[Signature]) }
346
+ #: Array[Signature]
403
347
  attr_reader :signatures
404
348
 
405
349
  # Returns the location of the method name, excluding parameters or the body
406
- sig { returns(Location) }
350
+ #: Location
407
351
  attr_reader :name_location
408
352
 
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
353
+ #: (String name, URI::Generic uri, Location location, Location name_location, String? comments, Array[Signature] signatures, Symbol visibility, Entry::Namespace? owner) -> void
421
354
  def initialize(name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
422
355
  super(name, uri, location, comments, visibility, owner)
423
356
  @signatures = signatures
@@ -436,24 +369,13 @@ module RubyIndexer
436
369
  # target in [rdoc-ref:Index#resolve]. If the right hand side contains a constant that doesn't exist, then it's not
437
370
  # possible to resolve the alias and it will remain an UnresolvedAlias until the right hand side constant exists
438
371
  class UnresolvedConstantAlias < Entry
439
- extend T::Sig
440
-
441
- sig { returns(String) }
372
+ #: String
442
373
  attr_reader :target
443
374
 
444
- sig { returns(T::Array[String]) }
375
+ #: Array[String]
445
376
  attr_reader :nesting
446
377
 
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
378
+ #: (String target, Array[String] nesting, String name, URI::Generic uri, Location location, String? comments) -> void
457
379
  def initialize(target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
458
380
  super(name, uri, location, comments)
459
381
 
@@ -464,12 +386,10 @@ module RubyIndexer
464
386
 
465
387
  # Alias represents a resolved alias, which points to an existing constant target
466
388
  class ConstantAlias < Entry
467
- extend T::Sig
468
-
469
- sig { returns(String) }
389
+ #: String
470
390
  attr_reader :target
471
391
 
472
- sig { params(target: String, unresolved_alias: UnresolvedConstantAlias).void }
392
+ #: (String target, UnresolvedConstantAlias unresolved_alias) -> void
473
393
  def initialize(target, unresolved_alias)
474
394
  super(
475
395
  unresolved_alias.name,
@@ -488,18 +408,10 @@ module RubyIndexer
488
408
 
489
409
  # Represents a class variable e.g.: @@a = 1
490
410
  class ClassVariable < Entry
491
- sig { returns(T.nilable(Entry::Namespace)) }
411
+ #: Entry::Namespace?
492
412
  attr_reader :owner
493
413
 
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
414
+ #: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
503
415
  def initialize(name, uri, location, comments, owner)
504
416
  super(name, uri, location, comments)
505
417
  @owner = owner
@@ -508,18 +420,10 @@ module RubyIndexer
508
420
 
509
421
  # Represents an instance variable e.g.: @a = 1
510
422
  class InstanceVariable < Entry
511
- sig { returns(T.nilable(Entry::Namespace)) }
423
+ #: Entry::Namespace?
512
424
  attr_reader :owner
513
425
 
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
426
+ #: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
523
427
  def initialize(name, uri, location, comments, owner)
524
428
  super(name, uri, location, comments)
525
429
  @owner = owner
@@ -530,24 +434,13 @@ module RubyIndexer
530
434
  # example, if we have `alias a b`, we create an unresolved alias for `a` because we aren't sure immediate what `b`
531
435
  # is referring to
532
436
  class UnresolvedMethodAlias < Entry
533
- extend T::Sig
534
-
535
- sig { returns(String) }
437
+ #: String
536
438
  attr_reader :new_name, :old_name
537
439
 
538
- sig { returns(T.nilable(Entry::Namespace)) }
440
+ #: Entry::Namespace?
539
441
  attr_reader :owner
540
442
 
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
443
+ #: (String new_name, String old_name, Entry::Namespace? owner, URI::Generic uri, Location location, String? comments) -> void
551
444
  def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
552
445
  super(new_name, uri, location, comments)
553
446
 
@@ -559,17 +452,13 @@ module RubyIndexer
559
452
 
560
453
  # A method alias is a resolved alias entry that points to the exact method target it refers to
561
454
  class MethodAlias < Entry
562
- extend T::Sig
563
-
564
- sig { returns(T.any(Member, MethodAlias)) }
455
+ #: (Member | MethodAlias)
565
456
  attr_reader :target
566
457
 
567
- sig { returns(T.nilable(Entry::Namespace)) }
458
+ #: Entry::Namespace?
568
459
  attr_reader :owner
569
460
 
570
- sig do
571
- params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias).void
572
- end
461
+ #: ((Member | MethodAlias) target, UnresolvedMethodAlias unresolved_alias) -> void
573
462
  def initialize(target, unresolved_alias)
574
463
  full_comments = +"Alias for #{target.name}\n"
575
464
  full_comments << "#{unresolved_alias.comments}\n"
@@ -583,20 +472,20 @@ module RubyIndexer
583
472
  )
584
473
 
585
474
  @target = target
586
- @owner = T.let(unresolved_alias.owner, T.nilable(Entry::Namespace))
475
+ @owner = unresolved_alias.owner #: Entry::Namespace?
587
476
  end
588
477
 
589
- sig { returns(String) }
478
+ #: -> String
590
479
  def decorated_parameters
591
480
  @target.decorated_parameters
592
481
  end
593
482
 
594
- sig { returns(String) }
483
+ #: -> String
595
484
  def formatted_signatures
596
485
  @target.formatted_signatures
597
486
  end
598
487
 
599
- sig { returns(T::Array[Signature]) }
488
+ #: -> Array[Signature]
600
489
  def signatures
601
490
  @target.signatures
602
491
  end
@@ -606,18 +495,16 @@ module RubyIndexer
606
495
  # However RBS can represent the concept of method overloading, with different return types based on the arguments
607
496
  # passed, so we need to store all the signatures.
608
497
  class Signature
609
- extend T::Sig
610
-
611
- sig { returns(T::Array[Parameter]) }
498
+ #: Array[Parameter]
612
499
  attr_reader :parameters
613
500
 
614
- sig { params(parameters: T::Array[Parameter]).void }
501
+ #: (Array[Parameter] parameters) -> void
615
502
  def initialize(parameters)
616
503
  @parameters = parameters
617
504
  end
618
505
 
619
506
  # Returns a string with the decorated names of the parameters of this member. E.g.: `(a, b = 1, c: 2)`
620
- sig { returns(String) }
507
+ #: -> String
621
508
  def format
622
509
  @parameters.map(&:decorated_name).join(", ")
623
510
  end
@@ -637,13 +524,13 @@ module RubyIndexer
637
524
  # foo(1)
638
525
  # foo(1, 2)
639
526
  # ```
640
- sig { params(arguments: T::Array[Prism::Node]).returns(T::Boolean) }
527
+ #: (Array[Prism::Node] arguments) -> bool
641
528
  def matches?(arguments)
642
529
  min_pos = 0
643
- max_pos = T.let(0, T.any(Integer, Float))
530
+ max_pos = 0 #: (Integer | Float)
644
531
  names = []
645
- has_forward = T.let(false, T::Boolean)
646
- has_keyword_rest = T.let(false, T::Boolean)
532
+ has_forward = false #: bool
533
+ has_keyword_rest = false #: bool
647
534
 
648
535
  @parameters.each do |param|
649
536
  case param
@@ -665,7 +552,8 @@ module RubyIndexer
665
552
  end
666
553
 
667
554
  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
555
+ keyword_args = keyword_hash_nodes.first #: as Prism::KeywordHashNode?
556
+ &.elements
669
557
  forwarding_arguments, positionals = positional_args.partition do |arg|
670
558
  arg.is_a?(Prism::ForwardingArgumentsNode)
671
559
  end
@@ -688,15 +576,7 @@ module RubyIndexer
688
576
  )
689
577
  end
690
578
 
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
579
+ #: (Array[Prism::Node] positional_args, Array[Prism::Node] forwarding_arguments, Array[Prism::Node]? keyword_args, Integer min_pos, (Integer | Float) max_pos) -> bool
700
580
  def positional_arguments_match?(positional_args, forwarding_arguments, keyword_args, min_pos, max_pos)
701
581
  # If the method accepts at least one positional argument and a splat has been passed
702
582
  (min_pos > 0 && positional_args.any? { |arg| arg.is_a?(Prism::SplatNode) }) ||
@@ -709,7 +589,7 @@ module RubyIndexer
709
589
  (min_pos == 0 && positional_args.empty?)
710
590
  end
711
591
 
712
- sig { params(args: T.nilable(T::Array[Prism::Node]), names: T::Array[Symbol]).returns(T::Boolean) }
592
+ #: (Array[Prism::Node]? args, Array[Symbol] names) -> bool
713
593
  def keyword_arguments_match?(args, names)
714
594
  return true unless args
715
595
  return true if args.any? { |arg| arg.is_a?(Prism::AssocSplatNode) }