diff --git a/lib/ruby_lsp/listeners/document_highlight.rb b/lib/ruby_lsp/listeners/document_highlight.rb index 551de5dff..c9a45a8ea 100644 --- a/lib/ruby_lsp/listeners/document_highlight.rb +++ b/lib/ruby_lsp/listeners/document_highlight.rb @@ -120,7 +120,7 @@ def initialize(response_builder, target, parent, dispatcher, position) [target, node_value(target)] when Prism::ModuleNode, Prism::ClassNode, Prism::SingletonClassNode, Prism::DefNode, Prism::CaseNode, Prism::WhileNode, Prism::UntilNode, Prism::ForNode, Prism::IfNode, Prism::UnlessNode - target + [target, nil] end @target = T.let(highlight_target, T.nilable(Prism::Node)) @@ -620,7 +620,8 @@ def node_value(node) sig { params(keyword_loc: T.nilable(Prism::Location), end_loc: T.nilable(Prism::Location)).void } def add_matching_end_highlights(keyword_loc, end_loc) - return unless keyword_loc && end_loc && end_loc.length.positive? + return unless keyword_loc && end_loc + return unless end_loc.length.positive? return unless covers_target_position?(keyword_loc) || covers_target_position?(end_loc) add_highlight(Constant::DocumentHighlightKind::TEXT, keyword_loc) diff --git a/lib/ruby_lsp/listeners/document_link.rb b/lib/ruby_lsp/listeners/document_link.rb index 554c88dd6..fcc34e881 100644 --- a/lib/ruby_lsp/listeners/document_link.rb +++ b/lib/ruby_lsp/listeners/document_link.rb @@ -131,7 +131,10 @@ def extract_document_link(node) path = uri.path return unless path - file_path = self.class.gem_paths.dig(uri.gem_name, gem_version, CGI.unescape(path)) + gem_name = uri.gem_name + return unless gem_name + + file_path = self.class.gem_paths.dig(gem_name, gem_version, CGI.unescape(path)) return if file_path.nil? @response_builder << Interface::DocumentLink.new( @@ -152,7 +155,10 @@ def resolve_version(uri) return @gem_version unless @gem_version.nil? || @gem_version.empty? - GEM_TO_VERSION_MAP[uri.gem_name] + gem_name = uri.gem_name + return unless gem_name + + GEM_TO_VERSION_MAP[gem_name] end end end diff --git a/lib/ruby_lsp/load_sorbet.rb b/lib/ruby_lsp/load_sorbet.rb index f954d1b77..0402051e9 100644 --- a/lib/ruby_lsp/load_sorbet.rb +++ b/lib/ruby_lsp/load_sorbet.rb @@ -6,11 +6,11 @@ begin T::Configuration.default_checked_level = :never # Suppresses call validation errors - T::Configuration.call_validation_error_handler = ->(*) {} + T::Configuration.call_validation_error_handler = ->(*arg) {} # Suppresses errors caused by T.cast, T.let, T.must, etc. - T::Configuration.inline_type_error_handler = ->(*) {} + T::Configuration.inline_type_error_handler = ->(*arg) {} # Suppresses errors caused by incorrect parameter ordering - T::Configuration.sig_validation_error_handler = ->(*) {} + T::Configuration.sig_validation_error_handler = ->(*arg) {} rescue # Need this rescue so that if another gem has # already set the checked level by the time we diff --git a/test/addon_test.rb b/test/addon_test.rb index 1b996f160..96e4bc445 100644 --- a/test/addon_test.rb +++ b/test/addon_test.rb @@ -99,8 +99,8 @@ def workspace_did_change_watched_files(changes); end end Addon.load_addons(@global_state, @outgoing_queue) - assert_equal(1, Addon.file_watcher_addons.length) - assert_instance_of(klass, Addon.file_watcher_addons.first) + addon = Addon.file_watcher_addons.find { |a| a.is_a?(klass) } + refute_nil(addon) end def test_get_an_addon_by_name diff --git a/test/server_test.rb b/test/server_test.rb index 201f886d2..d38210dd3 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -379,6 +379,10 @@ def test_shows_error_if_formatter_set_to_rubocop_but_rubocop_not_available }) @server.global_state.register_formatter("rubocop_internal", RubyLsp::Requests::Support::RuboCopFormatter.new) + + # Avoid trying to load add-ons because the RuboCop add-on will crash when the gem is artificially unloaded + @server.expects(:load_addons) + with_uninstalled_rubocop do @server.process_message({ method: "initialized" }) end diff --git a/vscode/src/test/suite/client.test.ts b/vscode/src/test/suite/client.test.ts index d0464310e..69610ba10 100644 --- a/vscode/src/test/suite/client.test.ts +++ b/vscode/src/test/suite/client.test.ts @@ -507,7 +507,7 @@ suite("Client", () => { }).timeout(20000); test("formatting", async () => { - const text = " def foo\n end"; + const text = "# frozen_string_literal: true\n def foo\n end"; await client.sendNotification("textDocument/didOpen", { textDocument: { @@ -532,9 +532,11 @@ suite("Client", () => { "def foo", "end", "", - ].join("\n"); + ] + .join("\n") + .trim(); - assert.strictEqual(response[0].newText, expected); + assert.strictEqual(response[0].newText.trim(), expected); }).timeout(20000); test("selection range", async () => {