Skip to content

Commit f51aa65

Browse files
committed
Forward all errors that translate to .cancelled from document diagnostics request
We were only forwarding `CancellationError` but depending on when cancellation happens, we would get `SKDError.cancelled`, which we would translate to empty diagnostics, causing the test to fail.
1 parent 045024d commit f51aa65

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,15 @@ extension SwiftLanguageService {
888888
buildSettings: buildSettings
889889
)
890890
return .full(diagnosticReport)
891-
} catch let error as CancellationError {
892-
throw error
893891
} catch {
894892
// VS Code does not request diagnostics again for a document if the diagnostics request failed.
895893
// Since sourcekit-lsp usually recovers from failures (e.g. after sourcekitd crashes), this is undesirable.
896894
// Instead of returning an error, return empty results.
895+
// Do forward cancellation because we don't want to clear diagnostics in the client if they cancel the diagnostic
896+
// request.
897+
if ResponseError(error) == .cancelled {
898+
throw error
899+
}
897900
logger.error(
898901
"""
899902
Loading diagnostic failed with the following error. Returning empty diagnostics.

Tests/SourceKitLSPTests/PullDiagnosticsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ final class PullDiagnosticsTests: XCTestCase {
337337
let requestID = project.testClient.send(
338338
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
339339
) { result in
340-
XCTAssertEqual(result.failure?.code, .cancelled)
340+
XCTAssertEqual(result, .failure(ResponseError.cancelled))
341341
diagnosticResponseReceived.fulfill()
342342
}
343343
project.testClient.send(CancelRequestNotification(id: requestID))

0 commit comments

Comments
 (0)