Skip to content

Commit 4c8aea2

Browse files
committed
Never return error for diagnostics request
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.
1 parent 9aee36b commit 4c8aea2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,20 @@ extension SwiftLanguageServer {
10621062
}
10631063

10641064
public func documentDiagnostic(_ req: DocumentDiagnosticsRequest) async throws -> DocumentDiagnosticReport {
1065-
return try await .full(fullDocumentDiagnosticReport(req))
1065+
do {
1066+
return try await .full(fullDocumentDiagnosticReport(req))
1067+
} catch {
1068+
// VS Code does not request diagnostics again for a document if the diagnostics request failed.
1069+
// Since sourcekit-lsp usually recovers from failures (e.g. after sourcekitd crashes), this is undesirable.
1070+
// Instead of returning an error, return empty results.
1071+
logger.error(
1072+
"""
1073+
Loading diagnostic failed with the following error. Returning empty diagnostics.
1074+
\(error.forLogging)
1075+
"""
1076+
)
1077+
return .full(RelatedFullDocumentDiagnosticReport(items: []))
1078+
}
10661079
}
10671080

10681081
private func fullDocumentDiagnosticReport(

0 commit comments

Comments
 (0)