Skip to content

Forward all errors that translate to .cancelled from document diagnostics request #1386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Sources/SourceKitLSP/Swift/SwiftLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,15 @@ extension SwiftLanguageService {
buildSettings: buildSettings
)
return .full(diagnosticReport)
} catch let error as CancellationError {
throw error
} catch {
// VS Code does not request diagnostics again for a document if the diagnostics request failed.
// Since sourcekit-lsp usually recovers from failures (e.g. after sourcekitd crashes), this is undesirable.
// Instead of returning an error, return empty results.
// Do forward cancellation because we don't want to clear diagnostics in the client if they cancel the diagnostic
// request.
if ResponseError(error) == .cancelled {
throw error
}
logger.error(
"""
Loading diagnostic failed with the following error. Returning empty diagnostics.
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/PullDiagnosticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ final class PullDiagnosticsTests: XCTestCase {
let requestID = project.testClient.send(
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
) { result in
XCTAssertEqual(result.failure?.code, .cancelled)
XCTAssertEqual(result, .failure(ResponseError.cancelled))
diagnosticResponseReceived.fulfill()
}
project.testClient.send(CancelRequestNotification(id: requestID))
Expand Down