ruby-lsp 0.23.11 → 0.23.13

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