Skip to content

Commit

Permalink
Go back to returning nil for cancelled requests (#3024)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
vinistock authored Jan 8, 2025
1 parent 460743e commit 6d5c5df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 1 addition & 5 deletions lib/ruby_lsp/base_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d5c5df

Please sign in to comment.