ruby-lsp 0.26.2 → 0.26.9

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/exe/ruby-lsp +7 -10
  4. data/exe/ruby-lsp-launcher +16 -3
  5. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +3 -2
  6. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +19 -0
  7. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +33 -27
  8. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +7 -2
  9. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +6 -2
  10. data/lib/ruby_lsp/base_server.rb +23 -12
  11. data/lib/ruby_lsp/global_state.rb +65 -33
  12. data/lib/ruby_lsp/listeners/definition.rb +34 -14
  13. data/lib/ruby_lsp/listeners/document_link.rb +62 -23
  14. data/lib/ruby_lsp/listeners/hover.rb +2 -2
  15. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +2 -2
  16. data/lib/ruby_lsp/requests/code_action_resolve.rb +33 -11
  17. data/lib/ruby_lsp/requests/code_actions.rb +20 -5
  18. data/lib/ruby_lsp/requests/completion_resolve.rb +8 -6
  19. data/lib/ruby_lsp/requests/support/package_url.rb +414 -0
  20. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +7 -1
  21. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +6 -10
  22. data/lib/ruby_lsp/requests/support/source_uri.rb +7 -6
  23. data/lib/ruby_lsp/requests/workspace_symbol.rb +20 -12
  24. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +3 -3
  25. data/lib/ruby_lsp/scripts/compose_bundle.rb +3 -3
  26. data/lib/ruby_lsp/scripts/compose_bundle_windows.rb +3 -1
  27. data/lib/ruby_lsp/server.rb +5 -2
  28. data/lib/ruby_lsp/setup_bundler.rb +68 -37
  29. data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +50 -27
  30. data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +1 -1
  31. data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +1 -1
  32. metadata +3 -16
  33. data/lib/ruby_indexer/test/class_variables_test.rb +0 -140
  34. data/lib/ruby_indexer/test/classes_and_modules_test.rb +0 -770
  35. data/lib/ruby_indexer/test/configuration_test.rb +0 -279
  36. data/lib/ruby_indexer/test/constant_test.rb +0 -402
  37. data/lib/ruby_indexer/test/enhancements_test.rb +0 -325
  38. data/lib/ruby_indexer/test/global_variable_test.rb +0 -49
  39. data/lib/ruby_indexer/test/index_test.rb +0 -2276
  40. data/lib/ruby_indexer/test/instance_variables_test.rb +0 -264
  41. data/lib/ruby_indexer/test/method_test.rb +0 -990
  42. data/lib/ruby_indexer/test/prefix_tree_test.rb +0 -150
  43. data/lib/ruby_indexer/test/rbs_indexer_test.rb +0 -381
  44. data/lib/ruby_indexer/test/reference_finder_test.rb +0 -395
  45. data/lib/ruby_indexer/test/test_case.rb +0 -57
  46. data/lib/ruby_indexer/test/uri_test.rb +0 -85
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c596f1104438061fe9ee2b890b980a7048e2137c10d34783d55defa0f17354
4
- data.tar.gz: b9f328146d02d36436a48385f1156a3a94ce9f321123220a2316a794ab253695
3
+ metadata.gz: 7b12b079fa54de3410e0d0ab2db9bf2241c6413c3c61d3ead21d4bbcc9b4e7d6
4
+ data.tar.gz: dede13048ef29f79079271c7d20d505160f8fe24d495863e08be96c95207c6bf
5
5
  SHA512:
6
- metadata.gz: 21c6b94baa433cf5c944a96f2ef8829f36ec81b0a093fb1e6fb5c53537698df6adc936f71ff2856bc68411d9ccefbd143cb75ee703d8d2b5a171e940faada191
7
- data.tar.gz: 7e84f101f485088c24e2afccaaa779f8cfdae3bb91798ec24f30199402bc3bbd5e142ece40a86de7845cb342b31d68be5c953383b0a0b081bf388b0574b25ab9
6
+ metadata.gz: 922edf8dadc38fa037d2c157c8e0b9bbbd3c759931ac6cda3070b615a3039597028672e8632507e80689f6a8f6cc793e7a1006a49bba28d72489f541e75f2fc3
7
+ data.tar.gz: 046d2d369c16a743f71750a9a6dfed945d8e21b43bb58ad357ce1098fd731dc4e7060ffebcc96e1b78a43a3b2571ac9e31d94dc6c25c380478cb54a979c0f461
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.26.2
1
+ 0.26.9
data/exe/ruby-lsp CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  require "optparse"
5
5
 
6
- original_args = ARGV.dup
7
6
  options = {}
8
7
  parser = OptionParser.new do |opts|
9
8
  opts.banner = "Usage: ruby-lsp [options]"
@@ -22,13 +21,6 @@ parser = OptionParser.new do |opts|
22
21
  options[:time_index] = true
23
22
  end
24
23
 
25
- opts.on(
26
- "--branch [BRANCH]",
27
- "Launch the Ruby LSP using the specified branch rather than the release version",
28
- ) do |branch|
29
- options[:branch] = branch
30
- end
31
-
32
24
  opts.on("--doctor", "Run troubleshooting steps") do
33
25
  options[:doctor] = true
34
26
  end
@@ -37,6 +29,10 @@ parser = OptionParser.new do |opts|
37
29
  options[:launcher] = true
38
30
  end
39
31
 
32
+ opts.on("--beta", "Use pre-release server gems") do
33
+ options[:beta] = true
34
+ end
35
+
40
36
  opts.on("-h", "--help", "Print this help") do
41
37
  puts opts.help
42
38
  puts
@@ -46,7 +42,7 @@ parser = OptionParser.new do |opts|
46
42
  end
47
43
 
48
44
  begin
49
- parser.parse!
45
+ parser.parse(ARGV)
50
46
  rescue OptionParser::InvalidOption => e
51
47
  warn(e)
52
48
  warn("")
@@ -66,6 +62,7 @@ if ENV["BUNDLE_GEMFILE"].nil?
66
62
  if options[:launcher]
67
63
  flags = []
68
64
  flags << "--debug" if options[:debug]
65
+ flags << "--beta" if options[:beta]
69
66
  exit exec(Gem.ruby, File.expand_path("ruby-lsp-launcher", __dir__), *flags)
70
67
  end
71
68
 
@@ -85,7 +82,7 @@ if ENV["BUNDLE_GEMFILE"].nil?
85
82
  base_command << " _#{env["BUNDLER_VERSION"]}_"
86
83
  end
87
84
 
88
- exit exec(env, "#{base_command} exec ruby-lsp #{original_args.join(" ")}".strip)
85
+ exit exec(env, "#{base_command} exec ruby-lsp #{ARGV.join(" ")}".strip)
89
86
  end
90
87
 
91
88
  $stdin.sync = true
@@ -20,6 +20,10 @@ reboot = false
20
20
  workspace_uri = ARGV.first
21
21
  raw_initialize_path = File.join(".ruby-lsp", "raw_initialize")
22
22
 
23
+ # Extract CLI options that affect bundle composition (e.g. --beta) from the arguments passed by the server
24
+ cli_options = {}
25
+ cli_options[:beta] = true if ARGV.include?("--beta")
26
+
23
27
  raw_initialize = if workspace_uri && !workspace_uri.start_with?("--")
24
28
  # If there's an argument without `--`, then it's the server asking to compose the bundle and passing to this
25
29
  # executable the workspace URI. We can't require gems at this point, so we built a fake initialize request manually
@@ -49,16 +53,20 @@ pid = if Gem.win_platform?
49
53
  ["-I", File.expand_path(path)]
50
54
  end
51
55
 
56
+ cli_flags = []
57
+ cli_flags << "--beta" if cli_options[:beta]
58
+
52
59
  Process.spawn(
53
60
  Gem.ruby,
54
61
  *load_path,
55
62
  File.expand_path("../lib/ruby_lsp/scripts/compose_bundle_windows.rb", __dir__),
56
63
  raw_initialize,
64
+ *cli_flags,
57
65
  )
58
66
  else
59
67
  fork do
60
68
  require_relative "../lib/ruby_lsp/scripts/compose_bundle"
61
- compose(raw_initialize)
69
+ compose(raw_initialize, **cli_options)
62
70
  end
63
71
  end
64
72
 
@@ -101,16 +109,21 @@ begin
101
109
  Bundler.setup
102
110
  $stderr.puts("Composed Bundle set up successfully")
103
111
  end
104
- rescue Bundler::GemNotFound, Bundler::GitError
112
+ rescue Bundler::GemNotFound, Bundler::GitError => e
105
113
  # Sometimes, we successfully set up the bundle, but users either change their Gemfile or uninstall gems from an
106
114
  # external process. If there's no install error, but the gem is still not found, then we need to attempt to start from
107
115
  # scratch
108
116
  unless install_error || ARGV.include?("--retry")
109
117
  $stderr.puts("Initial bundle compose succeeded, but Bundler.setup failed. Trying to restart from scratch...")
110
118
  File.write(raw_initialize_path, raw_initialize)
111
- exec(Gem.ruby, __FILE__, *ARGV, "--retry")
119
+
120
+ Bundler.with_unbundled_env do
121
+ exec(Gem.ruby, __FILE__, *ARGV, "--retry")
122
+ end
112
123
  end
113
124
 
125
+ setup_error = e
126
+ $stderr.puts("Failed to set up composed Bundle\n#{e.full_message}")
114
127
  $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
115
128
  rescue StandardError => e
116
129
  setup_error = e
@@ -227,7 +227,7 @@ module RubyIndexer
227
227
  others.uniq!
228
228
  others.map!(&:name)
229
229
 
230
- excluded.each do |dependency|
230
+ transitive_excluded = excluded.each_with_object([]) do |dependency, acc|
231
231
  next unless dependency.runtime?
232
232
 
233
233
  spec = dependency.to_spec
@@ -236,7 +236,7 @@ module RubyIndexer
236
236
  spec.dependencies.each do |transitive_dependency|
237
237
  next if others.include?(transitive_dependency.name)
238
238
 
239
- excluded << transitive_dependency
239
+ acc << transitive_dependency
240
240
  end
241
241
  rescue Gem::MissingSpecError
242
242
  # If a gem is scoped only to some specific platform, then its dependencies may not be installed either, but they
@@ -244,6 +244,7 @@ module RubyIndexer
244
244
  # just ignore if they're missing
245
245
  end
246
246
 
247
+ excluded.concat(transitive_excluded)
247
248
  excluded.uniq!
248
249
  excluded.map(&:name)
249
250
  rescue Bundler::GemfileNotFound
@@ -143,6 +143,7 @@ module RubyIndexer
143
143
  )
144
144
  else
145
145
  entry = Entry::SingletonClass.new(
146
+ @index.configuration,
146
147
  real_nesting,
147
148
  @uri,
148
149
  Location.from_prism_location(node.location, @code_units_cache),
@@ -326,6 +327,7 @@ module RubyIndexer
326
327
  signatures = [Entry::Signature.new(list_params(node.parameters))]
327
328
 
328
329
  @index.add(Entry::Method.new(
330
+ @index.configuration,
329
331
  method_name,
330
332
  @uri,
331
333
  location,
@@ -340,6 +342,7 @@ module RubyIndexer
340
342
  singleton = @index.existing_or_new_singleton_class(owner.name)
341
343
 
342
344
  @index.add(Entry::Method.new(
345
+ @index.configuration,
343
346
  method_name,
344
347
  @uri,
345
348
  location,
@@ -354,6 +357,7 @@ module RubyIndexer
354
357
  singleton = @index.existing_or_new_singleton_class(owner.name)
355
358
 
356
359
  @index.add(Entry::Method.new(
360
+ @index.configuration,
357
361
  method_name,
358
362
  @uri,
359
363
  Location.from_prism_location(node.location, @code_units_cache),
@@ -433,6 +437,7 @@ module RubyIndexer
433
437
  comments = collect_comments(node)
434
438
  @index.add(
435
439
  Entry::UnresolvedMethodAlias.new(
440
+ @index.configuration,
436
441
  method_name,
437
442
  node.old_name.slice,
438
443
  @owner_stack.last,
@@ -473,6 +478,7 @@ module RubyIndexer
473
478
  location = Location.from_prism_location(node_location, @code_units_cache)
474
479
 
475
480
  @index.add(Entry::Method.new(
481
+ @index.configuration,
476
482
  name,
477
483
  @uri,
478
484
  location,
@@ -490,6 +496,7 @@ module RubyIndexer
490
496
  name_loc = Location.from_prism_location(name_location, @code_units_cache)
491
497
 
492
498
  entry = Entry::Module.new(
499
+ @index.configuration,
493
500
  Index.actual_nesting(@stack, name),
494
501
  @uri,
495
502
  location,
@@ -504,6 +511,7 @@ module RubyIndexer
504
511
  def add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil)
505
512
  nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : Index.actual_nesting(@stack, name_or_nesting)
506
513
  entry = Entry::Class.new(
514
+ @index.configuration,
507
515
  nesting,
508
516
  @uri,
509
517
  Location.from_prism_location(full_location, @code_units_cache),
@@ -548,6 +556,7 @@ module RubyIndexer
548
556
  comments = collect_comments(node)
549
557
 
550
558
  @index.add(Entry::GlobalVariable.new(
559
+ @index.configuration,
551
560
  name,
552
561
  @uri,
553
562
  Location.from_prism_location(loc, @code_units_cache),
@@ -572,6 +581,7 @@ module RubyIndexer
572
581
  end
573
582
 
574
583
  @index.add(Entry::ClassVariable.new(
584
+ @index.configuration,
575
585
  name,
576
586
  @uri,
577
587
  Location.from_prism_location(loc, @code_units_cache),
@@ -594,6 +604,7 @@ module RubyIndexer
594
604
  end
595
605
 
596
606
  @index.add(Entry::InstanceVariable.new(
607
+ @index.configuration,
597
608
  name,
598
609
  @uri,
599
610
  Location.from_prism_location(loc, @code_units_cache),
@@ -656,6 +667,7 @@ module RubyIndexer
656
667
  comments = collect_comments(node)
657
668
  @index.add(
658
669
  Entry::UnresolvedMethodAlias.new(
670
+ @index.configuration,
659
671
  new_name_value,
660
672
  old_name_value,
661
673
  @owner_stack.last,
@@ -675,6 +687,7 @@ module RubyIndexer
675
687
  case value
676
688
  when Prism::ConstantReadNode, Prism::ConstantPathNode
677
689
  Entry::UnresolvedConstantAlias.new(
690
+ @index.configuration,
678
691
  value.slice,
679
692
  @stack.dup,
680
693
  name,
@@ -688,6 +701,7 @@ module RubyIndexer
688
701
  # If the right hand side is another constant assignment, we need to visit it because that constant has to be
689
702
  # indexed too
690
703
  Entry::UnresolvedConstantAlias.new(
704
+ @index.configuration,
691
705
  value.name.to_s,
692
706
  @stack.dup,
693
707
  name,
@@ -699,6 +713,7 @@ module RubyIndexer
699
713
  Prism::ConstantPathAndWriteNode
700
714
 
701
715
  Entry::UnresolvedConstantAlias.new(
716
+ @index.configuration,
702
717
  value.target.slice,
703
718
  @stack.dup,
704
719
  name,
@@ -708,6 +723,7 @@ module RubyIndexer
708
723
  )
709
724
  else
710
725
  Entry::Constant.new(
726
+ @index.configuration,
711
727
  name,
712
728
  @uri,
713
729
  Location.from_prism_location(node.location, @code_units_cache),
@@ -785,6 +801,7 @@ module RubyIndexer
785
801
 
786
802
  if reader
787
803
  @index.add(Entry::Accessor.new(
804
+ @index.configuration,
788
805
  name,
789
806
  @uri,
790
807
  Location.from_prism_location(loc, @code_units_cache),
@@ -797,6 +814,7 @@ module RubyIndexer
797
814
  next unless writer
798
815
 
799
816
  @index.add(Entry::Accessor.new(
817
+ @index.configuration,
800
818
  "#{name}=",
801
819
  @uri,
802
820
  Location.from_prism_location(loc, @code_units_cache),
@@ -879,6 +897,7 @@ module RubyIndexer
879
897
  singleton = @index.existing_or_new_singleton_class(entry_owner_name)
880
898
  location = Location.from_prism_location(argument.location, @code_units_cache)
881
899
  @index.add(Entry::Method.new(
900
+ @index.configuration,
882
901
  method_name,
883
902
  @uri,
884
903
  location,
@@ -3,6 +3,9 @@
3
3
 
4
4
  module RubyIndexer
5
5
  class Entry
6
+ #: Configuration
7
+ attr_reader :configuration
8
+
6
9
  #: String
7
10
  attr_reader :name
8
11
 
@@ -17,8 +20,9 @@ module RubyIndexer
17
20
  #: Symbol
18
21
  attr_accessor :visibility
19
22
 
20
- #: (String name, URI::Generic uri, Location location, String? comments) -> void
21
- def initialize(name, uri, location, comments)
23
+ #: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments) -> void
24
+ def initialize(configuration, name, uri, location, comments)
25
+ @configuration = configuration
22
26
  @name = name
23
27
  @uri = uri
24
28
  @comments = comments
@@ -82,7 +86,7 @@ module RubyIndexer
82
86
  correct_group.filter_map do |comment|
83
87
  content = comment.slice.chomp
84
88
 
85
- if content.valid_encoding?
89
+ if content.valid_encoding? && !content.match?(@configuration.magic_comment_regex)
86
90
  content.delete_prefix!("#")
87
91
  content.delete_prefix!(" ")
88
92
  content
@@ -121,13 +125,13 @@ module RubyIndexer
121
125
  #: Location
122
126
  attr_reader :name_location
123
127
 
124
- #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
125
- def initialize(nesting, uri, location, name_location, comments)
128
+ #: (Configuration configuration, Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
129
+ def initialize(configuration, nesting, uri, location, name_location, comments) # rubocop:disable Metrics/ParameterLists
126
130
  @name = nesting.join("::") #: String
127
131
  # The original nesting where this namespace was discovered
128
132
  @nesting = nesting
129
133
 
130
- super(@name, uri, location, comments)
134
+ super(configuration, @name, uri, location, comments)
131
135
 
132
136
  @name_location = name_location
133
137
  end
@@ -160,9 +164,9 @@ module RubyIndexer
160
164
  #: String?
161
165
  attr_reader :parent_class
162
166
 
163
- #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments, String? parent_class) -> void
164
- def initialize(nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
165
- super(nesting, uri, location, name_location, comments)
167
+ #: (Configuration configuration, Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments, String? parent_class) -> void
168
+ def initialize(configuration, nesting, uri, location, name_location, comments, parent_class) # rubocop:disable Metrics/ParameterLists
169
+ super(configuration, nesting, uri, location, name_location, comments)
166
170
  @parent_class = parent_class
167
171
  end
168
172
 
@@ -285,9 +289,9 @@ module RubyIndexer
285
289
  #: Entry::Namespace?
286
290
  attr_reader :owner
287
291
 
288
- #: (String name, URI::Generic uri, Location location, String? comments, Symbol visibility, Entry::Namespace? owner) -> void
289
- def initialize(name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
290
- super(name, uri, location, comments)
292
+ #: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments, Symbol visibility, Entry::Namespace? owner) -> void
293
+ def initialize(configuration, name, uri, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists
294
+ super(configuration, name, uri, location, comments)
291
295
  @visibility = visibility
292
296
  @owner = owner
293
297
  end
@@ -341,9 +345,9 @@ module RubyIndexer
341
345
  #: Location
342
346
  attr_reader :name_location
343
347
 
344
- #: (String name, URI::Generic uri, Location location, Location name_location, String? comments, Array[Signature] signatures, Symbol visibility, Entry::Namespace? owner) -> void
345
- def initialize(name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
346
- super(name, uri, location, comments, visibility, owner)
348
+ #: (Configuration configuration, String name, URI::Generic uri, Location location, Location name_location, String? comments, Array[Signature] signatures, Symbol visibility, Entry::Namespace? owner) -> void
349
+ def initialize(configuration, name, uri, location, name_location, comments, signatures, visibility, owner) # rubocop:disable Metrics/ParameterLists
350
+ super(configuration, name, uri, location, comments, visibility, owner)
347
351
  @signatures = signatures
348
352
  @name_location = name_location
349
353
  end
@@ -366,9 +370,9 @@ module RubyIndexer
366
370
  #: Array[String]
367
371
  attr_reader :nesting
368
372
 
369
- #: (String target, Array[String] nesting, String name, URI::Generic uri, Location location, String? comments) -> void
370
- def initialize(target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
371
- super(name, uri, location, comments)
373
+ #: (Configuration configuration, String target, Array[String] nesting, String name, URI::Generic uri, Location location, String? comments) -> void
374
+ def initialize(configuration, target, nesting, name, uri, location, comments) # rubocop:disable Metrics/ParameterLists
375
+ super(configuration, name, uri, location, comments)
372
376
 
373
377
  @target = target
374
378
  @nesting = nesting
@@ -383,6 +387,7 @@ module RubyIndexer
383
387
  #: (String target, UnresolvedConstantAlias unresolved_alias) -> void
384
388
  def initialize(target, unresolved_alias)
385
389
  super(
390
+ unresolved_alias.configuration,
386
391
  unresolved_alias.name,
387
392
  unresolved_alias.uri,
388
393
  unresolved_alias.location,
@@ -402,9 +407,9 @@ module RubyIndexer
402
407
  #: Entry::Namespace?
403
408
  attr_reader :owner
404
409
 
405
- #: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
406
- def initialize(name, uri, location, comments, owner)
407
- super(name, uri, location, comments)
410
+ #: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
411
+ def initialize(configuration, name, uri, location, comments, owner) # rubocop:disable Metrics/ParameterLists
412
+ super(configuration, name, uri, location, comments)
408
413
  @owner = owner
409
414
  end
410
415
  end
@@ -414,9 +419,9 @@ module RubyIndexer
414
419
  #: Entry::Namespace?
415
420
  attr_reader :owner
416
421
 
417
- #: (String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
418
- def initialize(name, uri, location, comments, owner)
419
- super(name, uri, location, comments)
422
+ #: (Configuration configuration, String name, URI::Generic uri, Location location, String? comments, Entry::Namespace? owner) -> void
423
+ def initialize(configuration, name, uri, location, comments, owner) # rubocop:disable Metrics/ParameterLists
424
+ super(configuration, name, uri, location, comments)
420
425
  @owner = owner
421
426
  end
422
427
  end
@@ -431,9 +436,9 @@ module RubyIndexer
431
436
  #: Entry::Namespace?
432
437
  attr_reader :owner
433
438
 
434
- #: (String new_name, String old_name, Entry::Namespace? owner, URI::Generic uri, Location location, String? comments) -> void
435
- def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
436
- super(new_name, uri, location, comments)
439
+ #: (Configuration configuration, String new_name, String old_name, Entry::Namespace? owner, URI::Generic uri, Location location, String? comments) -> void
440
+ def initialize(configuration, new_name, old_name, owner, uri, location, comments) # rubocop:disable Metrics/ParameterLists
441
+ super(configuration, new_name, uri, location, comments)
437
442
 
438
443
  @new_name = new_name
439
444
  @old_name = old_name
@@ -456,6 +461,7 @@ module RubyIndexer
456
461
  full_comments << target.comments
457
462
 
458
463
  super(
464
+ unresolved_alias.configuration,
459
465
  unresolved_alias.new_name,
460
466
  unresolved_alias.uri,
461
467
  unresolved_alias.location,
@@ -195,12 +195,13 @@ module RubyIndexer
195
195
  end
196
196
 
197
197
  # Fuzzy searches index entries based on Jaro-Winkler similarity. If no query is provided, all entries are returned
198
- #: (String? query) -> Array[Entry]
199
- def fuzzy_search(query)
198
+ #: (String? query) ?{ (Entry) -> bool? } -> Array[Entry]
199
+ def fuzzy_search(query, &condition)
200
200
  unless query
201
201
  entries = @entries.filter_map do |_name, entries|
202
202
  next if entries.first.is_a?(Entry::SingletonClass)
203
203
 
204
+ entries = entries.select(&condition) if condition
204
205
  entries
205
206
  end
206
207
 
@@ -212,6 +213,9 @@ module RubyIndexer
212
213
  results = @entries.filter_map do |name, entries|
213
214
  next if entries.first.is_a?(Entry::SingletonClass)
214
215
 
216
+ entries = entries.select(&condition) if condition
217
+ next if entries.empty?
218
+
215
219
  similarity = DidYouMean::JaroWinkler.distance(name.gsub("::", "").downcase, normalized_query)
216
220
  [entries, -similarity] if similarity > ENTRY_SIMILARITY_THRESHOLD
217
221
  end
@@ -710,6 +714,7 @@ module RubyIndexer
710
714
  attached_ancestor = self[name]&.first #: as !nil
711
715
 
712
716
  singleton = Entry::SingletonClass.new(
717
+ @configuration,
713
718
  [full_singleton_name],
714
719
  attached_ancestor.uri,
715
720
  attached_ancestor.location,
@@ -52,9 +52,9 @@ module RubyIndexer
52
52
  comments = comments_to_string(declaration)
53
53
  entry = if declaration.is_a?(RBS::AST::Declarations::Class)
54
54
  parent_class = declaration.super_class&.name&.name&.to_s
55
- Entry::Class.new(nesting, uri, location, location, comments, parent_class)
55
+ Entry::Class.new(@index.configuration, nesting, uri, location, location, comments, parent_class)
56
56
  else
57
- Entry::Module.new(nesting, uri, location, location, comments)
57
+ Entry::Module.new(@index.configuration, nesting, uri, location, location, comments)
58
58
  end
59
59
 
60
60
  add_declaration_mixins_to_entry(declaration, entry)
@@ -110,6 +110,7 @@ module RubyIndexer
110
110
  real_owner = member.singleton? ? @index.existing_or_new_singleton_class(owner.name) : owner
111
111
  signatures = signatures(member)
112
112
  @index.add(Entry::Method.new(
113
+ @index.configuration,
113
114
  name,
114
115
  uri,
115
116
  location,
@@ -243,6 +244,7 @@ module RubyIndexer
243
244
  def handle_constant(declaration, nesting, uri)
244
245
  fully_qualified_name = [*nesting, declaration.name.name.to_s].join("::")
245
246
  @index.add(Entry::Constant.new(
247
+ @index.configuration,
246
248
  fully_qualified_name,
247
249
  uri,
248
250
  to_ruby_indexer_location(declaration.location),
@@ -258,6 +260,7 @@ module RubyIndexer
258
260
  comments = comments_to_string(declaration)
259
261
 
260
262
  @index.add(Entry::GlobalVariable.new(
263
+ @index.configuration,
261
264
  name,
262
265
  uri,
263
266
  location,
@@ -271,6 +274,7 @@ module RubyIndexer
271
274
  comments = comments_to_string(member)
272
275
 
273
276
  entry = Entry::UnresolvedMethodAlias.new(
277
+ @index.configuration,
274
278
  member.new_name.to_s,
275
279
  member.old_name.to_s,
276
280
  owner_entry,
@@ -83,7 +83,7 @@ module RubyLsp
83
83
  # The following requests need to be executed in the main thread directly to avoid concurrency issues. Everything
84
84
  # else is pushed into the incoming queue
85
85
  case method
86
- when "initialize", "initialized", "rubyLsp/diagnoseState"
86
+ when "initialize", "initialized", "rubyLsp/diagnoseState", "$/cancelRequest"
87
87
  process_message(message)
88
88
  when "shutdown"
89
89
  @global_state.synchronize do
@@ -154,20 +154,31 @@ module RubyLsp
154
154
  def new_worker
155
155
  Thread.new do
156
156
  while (message = @incoming_queue.pop)
157
- id = message[:id]
157
+ handle_incoming_message(message)
158
+ end
159
+ end
160
+ end
158
161
 
159
- # Check if the request was cancelled before trying to process it
160
- @global_state.synchronize do
161
- if id && @cancelled_requests.include?(id)
162
- send_message(Result.new(id: id, response: nil))
163
- @cancelled_requests.delete(id)
164
- next
165
- end
166
- end
162
+ #: (Hash[Symbol, untyped]) -> void
163
+ def handle_incoming_message(message)
164
+ id = message[:id]
167
165
 
168
- process_message(message)
166
+ # Check if the request was cancelled before trying to process it
167
+ @global_state.synchronize do
168
+ if id && @cancelled_requests.delete(id)
169
+ send_message(Error.new(
170
+ id: id,
171
+ code: Constant::ErrorCodes::REQUEST_CANCELLED,
172
+ message: "Request #{id} was cancelled",
173
+ ))
174
+
175
+ return
169
176
  end
170
177
  end
178
+
179
+ process_message(message)
180
+ # Ensure we remove the request if it got cancelled while it was being processed
181
+ @cancelled_requests.delete(id)
171
182
  end
172
183
 
173
184
  #: ((Result | Error | Notification | Request) message) -> void
@@ -188,7 +199,7 @@ module RubyLsp
188
199
 
189
200
  #: (String message, ?type: Integer) -> void
190
201
  def send_log_message(message, type: Constant::MessageType::LOG)
191
- send_message(Notification.window_log_message(message, type: Constant::MessageType::LOG))
202
+ send_message(Notification.window_log_message(message, type: type))
192
203
  end
193
204
  end
194
205
  end