ruby-lsp 0.18.4 → 0.19.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/exe/ruby-lsp-check +1 -1
  4. data/lib/core_ext/uri.rb +9 -4
  5. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +6 -0
  6. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +66 -8
  7. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +63 -32
  8. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +8 -5
  9. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +38 -4
  10. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +324 -0
  11. data/lib/ruby_indexer/ruby_indexer.rb +1 -0
  12. data/lib/ruby_indexer/test/classes_and_modules_test.rb +23 -0
  13. data/lib/ruby_indexer/test/constant_test.rb +8 -0
  14. data/lib/ruby_indexer/test/enhancements_test.rb +2 -0
  15. data/lib/ruby_indexer/test/index_test.rb +3 -0
  16. data/lib/ruby_indexer/test/instance_variables_test.rb +12 -0
  17. data/lib/ruby_indexer/test/method_test.rb +10 -0
  18. data/lib/ruby_indexer/test/rbs_indexer_test.rb +14 -0
  19. data/lib/ruby_indexer/test/reference_finder_test.rb +242 -0
  20. data/lib/ruby_lsp/addon.rb +69 -7
  21. data/lib/ruby_lsp/erb_document.rb +9 -3
  22. data/lib/ruby_lsp/global_state.rb +8 -0
  23. data/lib/ruby_lsp/internal.rb +4 -0
  24. data/lib/ruby_lsp/listeners/completion.rb +1 -1
  25. data/lib/ruby_lsp/listeners/hover.rb +19 -0
  26. data/lib/ruby_lsp/requests/code_action_resolve.rb +9 -3
  27. data/lib/ruby_lsp/requests/completion.rb +1 -0
  28. data/lib/ruby_lsp/requests/completion_resolve.rb +29 -0
  29. data/lib/ruby_lsp/requests/definition.rb +1 -0
  30. data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
  31. data/lib/ruby_lsp/requests/hover.rb +1 -0
  32. data/lib/ruby_lsp/requests/range_formatting.rb +55 -0
  33. data/lib/ruby_lsp/requests/references.rb +146 -0
  34. data/lib/ruby_lsp/requests/rename.rb +196 -0
  35. data/lib/ruby_lsp/requests/signature_help.rb +6 -1
  36. data/lib/ruby_lsp/requests/support/formatter.rb +3 -0
  37. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +6 -0
  38. data/lib/ruby_lsp/requests/support/source_uri.rb +8 -1
  39. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +8 -0
  40. data/lib/ruby_lsp/ruby_document.rb +23 -8
  41. data/lib/ruby_lsp/server.rb +98 -10
  42. data/lib/ruby_lsp/static_docs.rb +15 -0
  43. data/lib/ruby_lsp/store.rb +12 -0
  44. data/lib/ruby_lsp/test_helper.rb +1 -1
  45. data/lib/ruby_lsp/type_inferrer.rb +6 -1
  46. data/static_docs/yield.md +81 -0
  47. metadata +20 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd64a8dbd26620a032266729f488c5ace69ead93e1cd8ae2677333d128bd72d4
4
- data.tar.gz: a7489c2405509d8764750c5946036d19106db75b6609524117f763b6279f45d1
3
+ metadata.gz: d900634d5328c8b4b5fcf799f807456bec3cdb94d6294c80fa9152bcf45aedde
4
+ data.tar.gz: b7661867d38331ec158312b10c7f530cbd58994ee94e8ff592f478e7e05efcb7
5
5
  SHA512:
6
- metadata.gz: dba4de24eca9cd3db51c94a2aef71c0b77e041172a5827d24b2a4b4079c41d955e0e990972258a6fd223766eedc20490f9af809da80ff46eb289a31d2fe2dbb7
7
- data.tar.gz: 49922ea026fe43cd23bfece5b5e1f6c10838dfe6e80a24c1dc5bd184d359361459af94083f773c86ce45f392ab4750f242a512136d367b8ccd95125ff13d42a9
6
+ metadata.gz: 8f7955f676bc5f231f990f04d8aea1a767165d4f2cac1e9514928014cd8a09eb68c60b4cd226a94b554dac88d77c2117ae3a3ea76bb66e68980974f1685d8970
7
+ data.tar.gz: 1b914d5607e5730139780cd1f172923db7878a7a0a4098daa1e17df8a1a7a2d8b6731b092baf7eeefc9f55605305e4d70d8cca8489f68a17bab532026c38e8b2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.4
1
+ 0.19.1
data/exe/ruby-lsp-check CHANGED
@@ -32,7 +32,7 @@ files.each_with_index do |file, index|
32
32
  })
33
33
 
34
34
  result = server.pop_response
35
- errors[file] = result.message if result.is_a?(RubyLsp::Error)
35
+ errors[file] = result if result.is_a?(RubyLsp::Error)
36
36
  ensure
37
37
  server.process_message({ method: "textDocument/didClose", params: { textDocument: { uri: uri } } })
38
38
  server.pop_response
data/lib/core_ext/uri.rb CHANGED
@@ -3,6 +3,11 @@
3
3
 
4
4
  module URI
5
5
  class Generic
6
+ # Avoid a deprecation warning with Ruby 3.4 where the default parser was changed to RFC3986.
7
+ # This condition must remain even after support for 3.4 has been dropped for users that have
8
+ # `uri` in their lockfile, decoupling it from the ruby version.
9
+ PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)
10
+
6
11
  class << self
7
12
  extend T::Sig
8
13
 
@@ -10,12 +15,12 @@ module URI
10
15
  def from_path(path:, fragment: nil, scheme: "file")
11
16
  # On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
12
17
  escaped_path = if /^[A-Z]:/i.match?(path)
13
- DEFAULT_PARSER.escape("/#{path}")
18
+ PARSER.escape("/#{path}")
14
19
  elsif path.start_with?("//?/")
15
20
  # Some paths on Windows start with "//?/". This is a special prefix that allows for long file paths
16
- DEFAULT_PARSER.escape(path.delete_prefix("//?"))
21
+ PARSER.escape(path.delete_prefix("//?"))
17
22
  else
18
- DEFAULT_PARSER.escape(path)
23
+ PARSER.escape(path)
19
24
  end
20
25
 
21
26
  build(scheme: scheme, path: escaped_path, fragment: fragment)
@@ -29,7 +34,7 @@ module URI
29
34
  parsed_path = path
30
35
  return unless parsed_path
31
36
 
32
- unescaped_path = DEFAULT_PARSER.unescape(parsed_path)
37
+ unescaped_path = PARSER.unescape(parsed_path)
33
38
 
34
39
  # On Windows, when we're getting the file system path back from the URI, we need to remove the leading forward
35
40
  # slash
@@ -19,9 +19,13 @@ module RubyIndexer
19
19
  sig { params(workspace_path: String).void }
20
20
  attr_writer :workspace_path
21
21
 
22
+ sig { returns(Encoding) }
23
+ attr_accessor :encoding
24
+
22
25
  sig { void }
23
26
  def initialize
24
27
  @workspace_path = T.let(Dir.pwd, String)
28
+ @encoding = T.let(Encoding::UTF_8, Encoding)
25
29
  @excluded_gems = T.let(initial_excluded_gems, T::Array[String])
26
30
  @included_gems = T.let([], T::Array[String])
27
31
  @excluded_patterns = T.let([File.join("**", "*_test.rb"), File.join("tmp", "**", "*")], T::Array[String])
@@ -235,6 +239,8 @@ module RubyIndexer
235
239
 
236
240
  excluded.uniq!
237
241
  excluded.map(&:name)
242
+ rescue Bundler::GemfileNotFound
243
+ []
238
244
  end
239
245
  end
240
246
  end
@@ -109,6 +109,7 @@ module RubyIndexer
109
109
  node.location,
110
110
  constant_path.location,
111
111
  comments,
112
+ @index.configuration.encoding,
112
113
  parent_class,
113
114
  )
114
115
 
@@ -132,7 +133,14 @@ module RubyIndexer
132
133
 
133
134
  comments = collect_comments(node)
134
135
 
135
- entry = Entry::Module.new(actual_nesting(name), @file_path, node.location, constant_path.location, comments)
136
+ entry = Entry::Module.new(
137
+ actual_nesting(name),
138
+ @file_path,
139
+ node.location,
140
+ constant_path.location,
141
+ comments,
142
+ @index.configuration.encoding,
143
+ )
136
144
 
137
145
  @owner_stack << entry
138
146
  @index.add(entry)
@@ -161,7 +169,12 @@ module RubyIndexer
161
169
 
162
170
  if existing_entries
163
171
  entry = T.must(existing_entries.first)
164
- entry.update_singleton_information(node.location, expression.location, collect_comments(node))
172
+ entry.update_singleton_information(
173
+ node.location,
174
+ expression.location,
175
+ collect_comments(node),
176
+ @index.configuration.encoding,
177
+ )
165
178
  else
166
179
  entry = Entry::SingletonClass.new(
167
180
  real_nesting,
@@ -169,6 +182,7 @@ module RubyIndexer
169
182
  node.location,
170
183
  expression.location,
171
184
  collect_comments(node),
185
+ @index.configuration.encoding,
172
186
  nil,
173
187
  )
174
188
  @index.add(entry, skip_prefix_tree: true)
@@ -329,6 +343,7 @@ module RubyIndexer
329
343
  node.location,
330
344
  node.name_loc,
331
345
  comments,
346
+ @index.configuration.encoding,
332
347
  [Entry::Signature.new(list_params(node.parameters))],
333
348
  current_visibility,
334
349
  @owner_stack.last,
@@ -345,6 +360,7 @@ module RubyIndexer
345
360
  node.location,
346
361
  node.name_loc,
347
362
  comments,
363
+ @index.configuration.encoding,
348
364
  [Entry::Signature.new(list_params(node.parameters))],
349
365
  current_visibility,
350
366
  singleton,
@@ -403,6 +419,7 @@ module RubyIndexer
403
419
  @file_path,
404
420
  node.new_name.location,
405
421
  comments,
422
+ @index.configuration.encoding,
406
423
  ),
407
424
  )
408
425
  end
@@ -433,7 +450,14 @@ module RubyIndexer
433
450
  owner = @index.existing_or_new_singleton_class(owner.name)
434
451
  end
435
452
 
436
- @index.add(Entry::InstanceVariable.new(name, @file_path, loc, collect_comments(node), owner))
453
+ @index.add(Entry::InstanceVariable.new(
454
+ name,
455
+ @file_path,
456
+ loc,
457
+ collect_comments(node),
458
+ @index.configuration.encoding,
459
+ owner,
460
+ ))
437
461
  end
438
462
 
439
463
  sig { params(node: Prism::CallNode).void }
@@ -496,6 +520,7 @@ module RubyIndexer
496
520
  @file_path,
497
521
  new_name.location,
498
522
  comments,
523
+ @index.configuration.encoding,
499
524
  ),
500
525
  )
501
526
  end
@@ -525,19 +550,43 @@ module RubyIndexer
525
550
  @index.add(
526
551
  case value
527
552
  when Prism::ConstantReadNode, Prism::ConstantPathNode
528
- Entry::UnresolvedConstantAlias.new(value.slice, @stack.dup, name, @file_path, node.location, comments)
553
+ Entry::UnresolvedConstantAlias.new(
554
+ value.slice,
555
+ @stack.dup,
556
+ name,
557
+ @file_path,
558
+ node.location,
559
+ comments,
560
+ @index.configuration.encoding,
561
+ )
529
562
  when Prism::ConstantWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOrWriteNode,
530
563
  Prism::ConstantOperatorWriteNode
531
564
 
532
565
  # If the right hand side is another constant assignment, we need to visit it because that constant has to be
533
566
  # indexed too
534
- Entry::UnresolvedConstantAlias.new(value.name.to_s, @stack.dup, name, @file_path, node.location, comments)
567
+ Entry::UnresolvedConstantAlias.new(
568
+ value.name.to_s,
569
+ @stack.dup,
570
+ name,
571
+ @file_path,
572
+ node.location,
573
+ comments,
574
+ @index.configuration.encoding,
575
+ )
535
576
  when Prism::ConstantPathWriteNode, Prism::ConstantPathOrWriteNode, Prism::ConstantPathOperatorWriteNode,
536
577
  Prism::ConstantPathAndWriteNode
537
578
 
538
- Entry::UnresolvedConstantAlias.new(value.target.slice, @stack.dup, name, @file_path, node.location, comments)
579
+ Entry::UnresolvedConstantAlias.new(
580
+ value.target.slice,
581
+ @stack.dup,
582
+ name,
583
+ @file_path,
584
+ node.location,
585
+ comments,
586
+ @index.configuration.encoding,
587
+ )
539
588
  else
540
- Entry::Constant.new(name, @file_path, node.location, comments)
589
+ Entry::Constant.new(name, @file_path, node.location, comments, @index.configuration.encoding)
541
590
  end,
542
591
  )
543
592
  end
@@ -600,7 +649,15 @@ module RubyIndexer
600
649
  next unless name && loc
601
650
 
602
651
  if reader
603
- @index.add(Entry::Accessor.new(name, @file_path, loc, comments, current_visibility, @owner_stack.last))
652
+ @index.add(Entry::Accessor.new(
653
+ name,
654
+ @file_path,
655
+ loc,
656
+ comments,
657
+ @index.configuration.encoding,
658
+ current_visibility,
659
+ @owner_stack.last,
660
+ ))
604
661
  end
605
662
 
606
663
  next unless writer
@@ -610,6 +667,7 @@ module RubyIndexer
610
667
  @file_path,
611
668
  loc,
612
669
  comments,
670
+ @index.configuration.encoding,
613
671
  current_visibility,
614
672
  @owner_stack.last,
615
673
  ))
@@ -33,9 +33,10 @@ module RubyIndexer
33
33
  file_path: String,
34
34
  location: T.any(Prism::Location, RubyIndexer::Location),
35
35
  comments: T.nilable(String),
36
+ encoding: Encoding,
36
37
  ).void
37
38
  end
38
- def initialize(name, file_path, location, comments)
39
+ def initialize(name, file_path, location, comments, encoding)
39
40
  @name = name
40
41
  @file_path = file_path
41
42
  @comments = comments
@@ -46,8 +47,8 @@ module RubyIndexer
46
47
  Location.new(
47
48
  location.start_line,
48
49
  location.end_line,
49
- location.start_column,
50
- location.end_column,
50
+ location.start_code_units_column(encoding),
51
+ location.end_code_units_column(encoding),
51
52
  )
52
53
  else
53
54
  location
@@ -109,6 +110,10 @@ module RubyIndexer
109
110
  else
110
111
  ""
111
112
  end
113
+ rescue Errno::ENOENT
114
+ # If the file was deleted, but the entry hasn't been removed yet (could happen due to concurrency), then we do
115
+ # not want to fail. Just set the comments to an empty string
116
+ ""
112
117
  end
113
118
  end
114
119
 
@@ -150,22 +155,23 @@ module RubyIndexer
150
155
  location: T.any(Prism::Location, RubyIndexer::Location),
151
156
  name_location: T.any(Prism::Location, Location),
152
157
  comments: T.nilable(String),
158
+ encoding: Encoding,
153
159
  ).void
154
160
  end
155
- def initialize(nesting, file_path, location, name_location, comments)
161
+ def initialize(nesting, file_path, location, name_location, comments, encoding) # rubocop:disable Metrics/ParameterLists
156
162
  @name = T.let(nesting.join("::"), String)
157
163
  # The original nesting where this namespace was discovered
158
164
  @nesting = nesting
159
165
 
160
- super(@name, file_path, location, comments)
166
+ super(@name, file_path, location, comments, encoding)
161
167
 
162
168
  @name_location = T.let(
163
169
  if name_location.is_a?(Prism::Location)
164
170
  Location.new(
165
171
  name_location.start_line,
166
172
  name_location.end_line,
167
- name_location.start_column,
168
- name_location.end_column,
173
+ name_location.start_code_units_column(encoding),
174
+ name_location.end_code_units_column(encoding),
169
175
  )
170
176
  else
171
177
  name_location
@@ -211,11 +217,12 @@ module RubyIndexer
211
217
  location: T.any(Prism::Location, RubyIndexer::Location),
212
218
  name_location: T.any(Prism::Location, Location),
213
219
  comments: T.nilable(String),
220
+ encoding: Encoding,
214
221
  parent_class: T.nilable(String),
215
222
  ).void
216
223
  end
217
- def initialize(nesting, file_path, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
218
- super(nesting, file_path, location, name_location, comments)
224
+ def initialize(nesting, file_path, location, name_location, comments, encoding, parent_class) # rubocop:disable Metrics/ParameterLists
225
+ super(nesting, file_path, location, name_location, comments, encoding)
219
226
  @parent_class = parent_class
220
227
  end
221
228
 
@@ -228,20 +235,27 @@ module RubyIndexer
228
235
  class SingletonClass < Class
229
236
  extend T::Sig
230
237
 
231
- sig { params(location: Prism::Location, name_location: Prism::Location, comments: T.nilable(String)).void }
232
- def update_singleton_information(location, name_location, comments)
238
+ sig do
239
+ params(
240
+ location: Prism::Location,
241
+ name_location: Prism::Location,
242
+ comments: T.nilable(String),
243
+ encoding: Encoding,
244
+ ).void
245
+ end
246
+ def update_singleton_information(location, name_location, comments, encoding)
233
247
  # Create a new RubyIndexer::Location object from the Prism location
234
248
  @location = Location.new(
235
249
  location.start_line,
236
250
  location.end_line,
237
- location.start_column,
238
- location.end_column,
251
+ location.start_code_units_column(encoding),
252
+ location.end_code_units_column(encoding),
239
253
  )
240
254
  @name_location = Location.new(
241
255
  name_location.start_line,
242
256
  name_location.end_line,
243
- name_location.start_column,
244
- name_location.end_column,
257
+ name_location.start_code_units_column(encoding),
258
+ name_location.end_code_units_column(encoding),
245
259
  )
246
260
  (@comments ||= +"") << comments if comments
247
261
  end
@@ -361,12 +375,13 @@ module RubyIndexer
361
375
  file_path: String,
362
376
  location: T.any(Prism::Location, RubyIndexer::Location),
363
377
  comments: T.nilable(String),
378
+ encoding: Encoding,
364
379
  visibility: Visibility,
365
380
  owner: T.nilable(Entry::Namespace),
366
381
  ).void
367
382
  end
368
- def initialize(name, file_path, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
369
- super(name, file_path, location, comments)
383
+ def initialize(name, file_path, location, comments, encoding, visibility, owner) # rubocop:disable Metrics/ParameterLists
384
+ super(name, file_path, location, comments, encoding)
370
385
  @visibility = visibility
371
386
  @owner = owner
372
387
  end
@@ -429,21 +444,22 @@ module RubyIndexer
429
444
  location: T.any(Prism::Location, RubyIndexer::Location),
430
445
  name_location: T.any(Prism::Location, Location),
431
446
  comments: T.nilable(String),
447
+ encoding: Encoding,
432
448
  signatures: T::Array[Signature],
433
449
  visibility: Visibility,
434
450
  owner: T.nilable(Entry::Namespace),
435
451
  ).void
436
452
  end
437
- def initialize(name, file_path, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
438
- super(name, file_path, location, comments, visibility, owner)
453
+ def initialize(name, file_path, location, name_location, comments, encoding, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
454
+ super(name, file_path, location, comments, encoding, visibility, owner)
439
455
  @signatures = signatures
440
456
  @name_location = T.let(
441
457
  if name_location.is_a?(Prism::Location)
442
458
  Location.new(
443
459
  name_location.start_line,
444
460
  name_location.end_line,
445
- name_location.start_column,
446
- name_location.end_column,
461
+ name_location.start_code_units_column(encoding),
462
+ name_location.end_code_units_column(encoding),
447
463
  )
448
464
  else
449
465
  name_location
@@ -480,10 +496,11 @@ module RubyIndexer
480
496
  file_path: String,
481
497
  location: T.any(Prism::Location, RubyIndexer::Location),
482
498
  comments: T.nilable(String),
499
+ encoding: Encoding,
483
500
  ).void
484
501
  end
485
- def initialize(target, nesting, name, file_path, location, comments) # rubocop:disable Metrics/ParameterLists
486
- super(name, file_path, location, comments)
502
+ def initialize(target, nesting, name, file_path, location, comments, encoding) # rubocop:disable Metrics/ParameterLists
503
+ super(name, file_path, location, comments, encoding)
487
504
 
488
505
  @target = target
489
506
  @nesting = nesting
@@ -497,15 +514,24 @@ module RubyIndexer
497
514
  sig { returns(String) }
498
515
  attr_reader :target
499
516
 
500
- sig { params(target: String, unresolved_alias: UnresolvedConstantAlias).void }
501
- def initialize(target, unresolved_alias)
502
- super(unresolved_alias.name, unresolved_alias.file_path, unresolved_alias.location, unresolved_alias.comments)
517
+ sig { params(target: String, unresolved_alias: UnresolvedConstantAlias, encoding: Encoding).void }
518
+ def initialize(target, unresolved_alias, encoding)
519
+ super(
520
+ unresolved_alias.name,
521
+ unresolved_alias.file_path,
522
+ unresolved_alias.location,
523
+ unresolved_alias.comments,
524
+ encoding
525
+ )
503
526
 
504
527
  @visibility = unresolved_alias.visibility
505
528
  @target = target
506
529
  end
507
530
  end
508
531
 
532
+ # Represents a global variable e.g.: $DEBUG
533
+ class GlobalVariable < Entry; end
534
+
509
535
  # Represents an instance variable e.g.: @a = 1
510
536
  class InstanceVariable < Entry
511
537
  sig { returns(T.nilable(Entry::Namespace)) }
@@ -517,11 +543,12 @@ module RubyIndexer
517
543
  file_path: String,
518
544
  location: T.any(Prism::Location, RubyIndexer::Location),
519
545
  comments: T.nilable(String),
546
+ encoding: Encoding,
520
547
  owner: T.nilable(Entry::Namespace),
521
548
  ).void
522
549
  end
523
- def initialize(name, file_path, location, comments, owner)
524
- super(name, file_path, location, comments)
550
+ def initialize(name, file_path, location, comments, encoding, owner) # rubocop:disable Metrics/ParameterLists
551
+ super(name, file_path, location, comments, encoding)
525
552
  @owner = owner
526
553
  end
527
554
  end
@@ -546,10 +573,11 @@ module RubyIndexer
546
573
  file_path: String,
547
574
  location: T.any(Prism::Location, RubyIndexer::Location),
548
575
  comments: T.nilable(String),
576
+ encoding: Encoding,
549
577
  ).void
550
578
  end
551
- def initialize(new_name, old_name, owner, file_path, location, comments) # rubocop:disable Metrics/ParameterLists
552
- super(new_name, file_path, location, comments)
579
+ def initialize(new_name, old_name, owner, file_path, location, comments, encoding) # rubocop:disable Metrics/ParameterLists
580
+ super(new_name, file_path, location, comments, encoding)
553
581
 
554
582
  @new_name = new_name
555
583
  @old_name = old_name
@@ -567,8 +595,10 @@ module RubyIndexer
567
595
  sig { returns(T.nilable(Entry::Namespace)) }
568
596
  attr_reader :owner
569
597
 
570
- sig { params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias).void }
571
- def initialize(target, unresolved_alias)
598
+ sig do
599
+ params(target: T.any(Member, MethodAlias), unresolved_alias: UnresolvedMethodAlias, encoding: Encoding).void
600
+ end
601
+ def initialize(target, unresolved_alias, encoding)
572
602
  full_comments = +"Alias for #{target.name}\n"
573
603
  full_comments << "#{unresolved_alias.comments}\n"
574
604
  full_comments << target.comments
@@ -578,6 +608,7 @@ module RubyIndexer
578
608
  unresolved_alias.file_path,
579
609
  unresolved_alias.location,
580
610
  full_comments,
611
+ encoding
581
612
  )
582
613
 
583
614
  @target = target
@@ -665,6 +665,7 @@ module RubyIndexer
665
665
  attached_ancestor.location,
666
666
  attached_ancestor.name_location,
667
667
  nil,
668
+ @configuration.encoding,
668
669
  nil,
669
670
  )
670
671
  add(singleton, skip_prefix_tree: true)
@@ -676,11 +677,13 @@ module RubyIndexer
676
677
  sig do
677
678
  type_parameters(:T).params(
678
679
  path: String,
679
- type: T::Class[T.all(T.type_parameter(:T), Entry)],
680
- ).returns(T.nilable(T::Array[T.type_parameter(:T)]))
680
+ type: T.nilable(T::Class[T.all(T.type_parameter(:T), Entry)]),
681
+ ).returns(T.nilable(T.any(T::Array[Entry], T::Array[T.type_parameter(:T)])))
681
682
  end
682
- def entries_for(path, type)
683
+ def entries_for(path, type = nil)
683
684
  entries = @files_to_entries[path]
685
+ return entries unless type
686
+
684
687
  entries&.grep(type)
685
688
  end
686
689
 
@@ -856,7 +859,7 @@ module RubyIndexer
856
859
  return entry unless target
857
860
 
858
861
  target_name = T.must(target.first).name
859
- resolved_alias = Entry::ConstantAlias.new(target_name, entry)
862
+ resolved_alias = Entry::ConstantAlias.new(target_name, entry, @configuration.encoding)
860
863
 
861
864
  # Replace the UnresolvedAlias by a resolved one so that we don't have to do this again later
862
865
  original_entries = T.must(@entries[alias_name])
@@ -1047,7 +1050,7 @@ module RubyIndexer
1047
1050
  target_method_entries = resolve_method(entry.old_name, receiver_name, seen_names)
1048
1051
  return entry unless target_method_entries
1049
1052
 
1050
- resolved_alias = Entry::MethodAlias.new(T.must(target_method_entries.first), entry)
1053
+ resolved_alias = Entry::MethodAlias.new(T.must(target_method_entries.first), entry, @configuration.encoding)
1051
1054
  original_entries = T.must(@entries[new_name])
1052
1055
  original_entries.delete(entry)
1053
1056
  original_entries << resolved_alias
@@ -5,6 +5,8 @@ module RubyIndexer
5
5
  class RBSIndexer
6
6
  extend T::Sig
7
7
 
8
+ HAS_UNTYPED_FUNCTION = T.let(!!defined?(RBS::Types::UntypedFunction), T::Boolean)
9
+
8
10
  sig { params(index: Index).void }
9
11
  def initialize(index)
10
12
  @index = index
@@ -42,6 +44,8 @@ module RubyIndexer
42
44
  when RBS::AST::Declarations::Constant
43
45
  namespace_nesting = declaration.name.namespace.path.map(&:to_s)
44
46
  handle_constant(declaration, namespace_nesting, pathname.to_s)
47
+ when RBS::AST::Declarations::Global
48
+ handle_global_variable(declaration, pathname)
45
49
  else # rubocop:disable Style/EmptyElse
46
50
  # Other kinds not yet handled
47
51
  end
@@ -57,9 +61,9 @@ module RubyIndexer
57
61
  comments = comments_to_string(declaration)
58
62
  entry = if declaration.is_a?(RBS::AST::Declarations::Class)
59
63
  parent_class = declaration.super_class&.name&.name&.to_s
60
- Entry::Class.new(nesting, file_path, location, location, comments, parent_class)
64
+ Entry::Class.new(nesting, file_path, location, location, comments, @index.configuration.encoding, parent_class)
61
65
  else
62
- Entry::Module.new(nesting, file_path, location, location, comments)
66
+ Entry::Module.new(nesting, file_path, location, location, comments, @index.configuration.encoding)
63
67
  end
64
68
  add_declaration_mixins_to_entry(declaration, entry)
65
69
  @index.add(entry)
@@ -126,7 +130,17 @@ module RubyIndexer
126
130
 
127
131
  real_owner = member.singleton? ? @index.existing_or_new_singleton_class(owner.name) : owner
128
132
  signatures = signatures(member)
129
- @index.add(Entry::Method.new(name, file_path, location, location, comments, signatures, visibility, real_owner))
133
+ @index.add(Entry::Method.new(
134
+ name,
135
+ file_path,
136
+ location,
137
+ location,
138
+ comments,
139
+ @index.configuration.encoding,
140
+ signatures,
141
+ visibility,
142
+ real_owner,
143
+ ))
130
144
  end
131
145
 
132
146
  sig { params(member: RBS::AST::Members::MethodDefinition).returns(T::Array[Entry::Signature]) }
@@ -151,7 +165,7 @@ module RubyIndexer
151
165
 
152
166
  # Untyped functions are a new RBS feature (since v3.6.0) to declare methods that accept any parameters. For our
153
167
  # purposes, accepting any argument is equivalent to `...`
154
- if defined?(RBS::Types::UntypedFunction) && function.is_a?(RBS::Types::UntypedFunction)
168
+ if HAS_UNTYPED_FUNCTION && function.is_a?(RBS::Types::UntypedFunction)
155
169
  [Entry::ForwardingParameter.new]
156
170
  else
157
171
  []
@@ -255,6 +269,24 @@ module RubyIndexer
255
269
  file_path,
256
270
  to_ruby_indexer_location(declaration.location),
257
271
  comments_to_string(declaration),
272
+ @index.configuration.encoding,
273
+ ))
274
+ end
275
+
276
+ sig { params(declaration: RBS::AST::Declarations::Global, pathname: Pathname).void }
277
+ def handle_global_variable(declaration, pathname)
278
+ name = declaration.name.to_s
279
+ file_path = pathname.to_s
280
+ location = to_ruby_indexer_location(declaration.location)
281
+ comments = comments_to_string(declaration)
282
+ encoding = @index.configuration.encoding
283
+
284
+ @index.add(Entry::GlobalVariable.new(
285
+ name,
286
+ file_path,
287
+ location,
288
+ comments,
289
+ encoding,
258
290
  ))
259
291
  end
260
292
 
@@ -270,6 +302,7 @@ module RubyIndexer
270
302
  file_path,
271
303
  to_ruby_indexer_location(member.location),
272
304
  comments,
305
+ @index.configuration.encoding,
273
306
  )
274
307
 
275
308
  @index.add(entry)
@@ -280,6 +313,7 @@ module RubyIndexer
280
313
  RBS::AST::Declarations::Class,
281
314
  RBS::AST::Declarations::Module,
282
315
  RBS::AST::Declarations::Constant,
316
+ RBS::AST::Declarations::Global,
283
317
  RBS::AST::Members::MethodDefinition,
284
318
  RBS::AST::Members::Alias,
285
319
  )).returns(T.nilable(String))