From f0e87100bf34cc30d8da875c385d257c6a345a18 Mon Sep 17 00:00:00 2001 From: Louis Qian Date: Sat, 22 Jun 2024 14:57:27 -0500 Subject: [PATCH] fix: adding try & orLog where necesary --- Sources/SourceKitLSP/Rename.swift | 2 +- Sources/SourceKitLSP/Swift/SwiftLanguageService.swift | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/SourceKitLSP/Rename.swift b/Sources/SourceKitLSP/Rename.swift index 80a446206..1ae4c1309 100644 --- a/Sources/SourceKitLSP/Rename.swift +++ b/Sources/SourceKitLSP/Rename.swift @@ -345,7 +345,7 @@ extension SwiftLanguageService { in uri: DocumentURI, name: CompoundDeclName ) async throws -> String { - guard let snapshot = documentManager.latestSnapshotOrDisk(uri, language: .swift) else { + guard let snapshot = try? documentManager.latestSnapshotOrDisk(uri, language: .swift) else { throw ResponseError.unknown("Failed to get contents of \(uri.forLogging) to translate Swift name to clang name") } diff --git a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift index 1caaa49c7..5b6d4ac84 100644 --- a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift +++ b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift @@ -209,7 +209,7 @@ public actor SwiftLanguageService: LanguageService, Sendable { self.diagnosticReportManager = DiagnosticReportManager( sourcekitd: self.sourcekitd, syntaxTreeManager: syntaxTreeManager, - documentManager: documentManager, + documentManager: try documentManager, clientHasDiagnosticsCodeDescriptionSupport: await self.clientHasDiagnosticsCodeDescriptionSupport ) @@ -437,7 +437,7 @@ extension SwiftLanguageService { cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri) await diagnosticReportManager.removeItemsFromCache(with: notification.textDocument.uri) - guard let snapshot = self.documentManager.open(notification) else { + guard let snapshot = try? self.documentManager.open(notification) else { // Already logged failure. return } @@ -454,7 +454,9 @@ extension SwiftLanguageService { inFlightPublishDiagnosticsTasks[notification.textDocument.uri] = nil await diagnosticReportManager.removeItemsFromCache(with: notification.textDocument.uri) - self.documentManager.close(notification) + orLog("Connection to the editor closed") { + try? self.documentManager.close(notification) + } let req = closeDocumentSourcekitdRequest(uri: notification.textDocument.uri) _ = try? await self.sourcekitd.send(req, fileContents: nil) @@ -548,7 +550,7 @@ extension SwiftLanguageService { let replacement: String } - guard let (preEditSnapshot, postEditSnapshot, edits) = self.documentManager.edit(notification) else { + guard let (preEditSnapshot, postEditSnapshot, edits) = try? self.documentManager.edit(notification) else { return }