From 6d5c5df17e4ff3825632bd3cb04c11d54d0dff8c Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 8 Jan 2025 12:08:27 -0500 Subject: [PATCH] Go back to returning `nil` for cancelled requests (#3024) ### Motivation This is a temporary revert to fix #3019 while we understand the correct response flow for retried cancelled requests. This PR reverts the behaviour introduced in #2939, which didn't cause problems for NeoVim. ### Implementation I didn't perform a full revert of every single change, since we do want to ensure that we're following the spec. I just stopped returning the error and went back to returning a `nil` response until we figure out what's going on. ### Automated Tests Changed the test so that it asserts the current behaviour. We'll switch it back later. --- lib/ruby_lsp/base_server.rb | 6 +----- test/server_test.rb | 7 +++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/ruby_lsp/base_server.rb b/lib/ruby_lsp/base_server.rb index 1cc086763..49c813a88 100644 --- a/lib/ruby_lsp/base_server.rb +++ b/lib/ruby_lsp/base_server.rb @@ -158,11 +158,7 @@ def new_worker # Check if the request was cancelled before trying to process it @global_state.synchronize do if id && @cancelled_requests.include?(id) - send_message(Error.new( - id: id, - code: Constant::ErrorCodes::REQUEST_CANCELLED, - message: "Request #{id} was cancelled", - )) + send_message(Result.new(id: id, response: nil)) @cancelled_requests.delete(id) next end diff --git a/test/server_test.rb b/test/server_test.rb index 735ace549..b430deb33 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -751,7 +751,7 @@ def test_requests_to_a_non_existing_position_return_error assert_match("Request textDocument/completion failed to find the target position.", error.message) end - def test_cancelling_requests_returns_expected_error_code + def test_cancelling_requests_returns_nil uri = URI("file:///foo.rb") @server.process_message({ @@ -791,9 +791,8 @@ def test_cancelling_requests_returns_expected_error_code mutex.unlock thread.join - error = find_message(RubyLsp::Error) - assert_equal(RubyLsp::Constant::ErrorCodes::REQUEST_CANCELLED, error.code) - assert_equal("Request 1 was cancelled", error.message) + result = find_message(RubyLsp::Result) + assert_nil(result.response) end def test_unsaved_changes_are_indexed_when_computing_automatic_features