Skip to content

Commit f293741

Browse files
authored
Merge pull request #981 from ahoppen/ahoppen/never-error-for-diagnostics-request
Never return error for diagnostics request
2 parents b7cc49b + 4c8aea2 commit f293741

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
@@ -1053,7 +1053,20 @@ extension SwiftLanguageServer {
10531053
}
10541054

10551055
public func documentDiagnostic(_ req: DocumentDiagnosticsRequest) async throws -> DocumentDiagnosticReport {
1056-
return try await .full(fullDocumentDiagnosticReport(req))
1056+
do {
1057+
return try await .full(fullDocumentDiagnosticReport(req))
1058+
} catch {
1059+
// VS Code does not request diagnostics again for a document if the diagnostics request failed.
1060+
// Since sourcekit-lsp usually recovers from failures (e.g. after sourcekitd crashes), this is undesirable.
1061+
// Instead of returning an error, return empty results.
1062+
logger.error(
1063+
"""
1064+
Loading diagnostic failed with the following error. Returning empty diagnostics.
1065+
\(error.forLogging)
1066+
"""
1067+
)
1068+
return .full(RelatedFullDocumentDiagnosticReport(items: []))
1069+
}
10571070
}
10581071

10591072
private func fullDocumentDiagnosticReport(

0 commit comments

Comments
 (0)