Skip to content

Commit 87dd95e

Browse files
authored
Merge pull request #927 from ahoppen/ahoppen/mini-improvements
Minor improvements to SwiftLanguageServer.swift
2 parents b7063a8 + 69d22da commit 87dd95e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ extension SwiftLanguageServer {
367367
/// If the client doesn't support pull diagnostics, compute diagnostics for the latest version of the given document
368368
/// and send a `PublishDiagnosticsNotification` to the client for it.
369369
private func publishDiagnosticsIfNeeded(for document: DocumentURI) {
370+
withLoggingScope("publish-diagnostics") {
371+
publishDiagnosticsIfNeededImpl(for: document)
372+
}
373+
}
374+
375+
private func publishDiagnosticsIfNeededImpl(for document: DocumentURI) {
370376
guard enablePublishDiagnostics else {
371377
return
372378
}
@@ -383,24 +389,31 @@ extension SwiftLanguageServer {
383389
// Sleep for a little bit until triggering the diagnostic generation. This effectively de-bounces diagnostic
384390
// generation since any later edit will cancel the previous in-flight task, which will thus never go on to send
385391
// 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+
)
387395
} catch {
388396
return
389397
}
390398
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+
)
392402

393403
await sourceKitServer.sendNotificationToClient(
394404
PublishDiagnosticsNotification(
395405
uri: document,
396406
diagnostics: diagnosticReport.items
397407
)
398408
)
409+
} catch is CancellationError {
399410
} catch {
400-
logger.fault("""
411+
logger.fault(
412+
"""
401413
Failed to get diagnostics
402414
\(error.forLogging)
403-
""")
415+
"""
416+
)
404417
}
405418
}
406419
}
@@ -1133,7 +1146,9 @@ extension SwiftLanguageServer {
11331146
return try await .full(fullDocumentDiagnosticReport(req))
11341147
}
11351148

1136-
private func fullDocumentDiagnosticReport(_ req: DocumentDiagnosticsRequest) async throws -> RelatedFullDocumentDiagnosticReport {
1149+
private func fullDocumentDiagnosticReport(
1150+
_ req: DocumentDiagnosticsRequest
1151+
) async throws -> RelatedFullDocumentDiagnosticReport {
11371152
guard let snapshot = documentManager.latestSnapshot(req.textDocument.uri) else {
11381153
throw ResponseError.unknown("failed to find snapshot for url \(req.textDocument.uri.forLogging)")
11391154
}

0 commit comments

Comments
 (0)