Skip to content

Commit

Permalink
Never return error for diagnostics request
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahoppen committed Nov 27, 2023
1 parent 9aee36b commit 32cb77f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,20 @@ extension SwiftLanguageServer {
}

public func documentDiagnostic(_ req: DocumentDiagnosticsRequest) async throws -> DocumentDiagnosticReport {
return try await .full(fullDocumentDiagnosticReport(req))
do {
return try await .full(fullDocumentDiagnosticReport(req))
} 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.
logger.error(
"""
Loading diagnostic failed with the following error. Returning empty diagnostics.
\(error.forLogging)
"""
)
return .full(RelatedFullDocumentDiagnosticReport(items: []))
}
}

private func fullDocumentDiagnosticReport(
Expand Down

0 comments on commit 32cb77f

Please sign in to comment.