@@ -367,6 +367,12 @@ extension SwiftLanguageServer {
367
367
/// If the client doesn't support pull diagnostics, compute diagnostics for the latest version of the given document
368
368
/// and send a `PublishDiagnosticsNotification` to the client for it.
369
369
private func publishDiagnosticsIfNeeded( for document: DocumentURI ) {
370
+ withLoggingScope ( " publish-diagnostics " ) {
371
+ publishDiagnosticsIfNeededImpl ( for: document)
372
+ }
373
+ }
374
+
375
+ private func publishDiagnosticsIfNeededImpl( for document: DocumentURI ) {
370
376
guard enablePublishDiagnostics else {
371
377
return
372
378
}
@@ -383,24 +389,31 @@ extension SwiftLanguageServer {
383
389
// Sleep for a little bit until triggering the diagnostic generation. This effectively de-bounces diagnostic
384
390
// generation since any later edit will cancel the previous in-flight task, which will thus never go on to send
385
391
// the `DocumentDiagnosticsRequest`.
386
- try await Task . sleep ( nanoseconds: UInt64 ( sourceKitServer. options. swiftPublishDiagnosticsDebounceDuration * 1_000_000_000 ) )
392
+ try await Task . sleep (
393
+ nanoseconds: UInt64 ( sourceKitServer. options. swiftPublishDiagnosticsDebounceDuration * 1_000_000_000 )
394
+ )
387
395
} catch {
388
396
return
389
397
}
390
398
do {
391
- let diagnosticReport = try await self . fullDocumentDiagnosticReport ( DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( document) ) )
399
+ let diagnosticReport = try await self . fullDocumentDiagnosticReport (
400
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( document) )
401
+ )
392
402
393
403
await sourceKitServer. sendNotificationToClient (
394
404
PublishDiagnosticsNotification (
395
405
uri: document,
396
406
diagnostics: diagnosticReport. items
397
407
)
398
408
)
409
+ } catch is CancellationError {
399
410
} catch {
400
- logger. fault ( """
411
+ logger. fault (
412
+ """
401
413
Failed to get diagnostics
402
414
\( error. forLogging)
403
- """ )
415
+ """
416
+ )
404
417
}
405
418
}
406
419
}
@@ -1133,7 +1146,9 @@ extension SwiftLanguageServer {
1133
1146
return try await . full( fullDocumentDiagnosticReport ( req) )
1134
1147
}
1135
1148
1136
- private func fullDocumentDiagnosticReport( _ req: DocumentDiagnosticsRequest ) async throws -> RelatedFullDocumentDiagnosticReport {
1149
+ private func fullDocumentDiagnosticReport(
1150
+ _ req: DocumentDiagnosticsRequest
1151
+ ) async throws -> RelatedFullDocumentDiagnosticReport {
1137
1152
guard let snapshot = documentManager. latestSnapshot ( req. textDocument. uri) else {
1138
1153
throw ResponseError . unknown ( " failed to find snapshot for url \( req. textDocument. uri. forLogging) " )
1139
1154
}
0 commit comments