diff --git a/CodeEdit/AppDelegate.swift b/CodeEdit/AppDelegate.swift index 7e0cbc2a3..37c4991ff 100644 --- a/CodeEdit/AppDelegate.swift +++ b/CodeEdit/AppDelegate.swift @@ -254,17 +254,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject { /// Terminates running language servers. Used during app termination to ensure resources are freed. private func terminateLanguageServers() { Task { - await withTaskGroup(of: Void.self) { group in - await lspService.languageClients.forEach { (key, value) in - group.addTask { - do { - try await value.shutdown() - } catch { - self.logger.error("Shutting down \(key.languageId.rawValue): Error \(error)") - } - } - } - } + await lspService.stopAllServers() await MainActor.run { NSApplication.shared.reply(toApplicationShouldTerminate: true) } diff --git a/CodeEdit/Features/LSP/Service/LSPService.swift b/CodeEdit/Features/LSP/Service/LSPService.swift index 095696bbd..0c4b5a812 100644 --- a/CodeEdit/Features/LSP/Service/LSPService.swift +++ b/CodeEdit/Features/LSP/Service/LSPService.swift @@ -269,10 +269,24 @@ final class LSPService: ObservableObject { } /// Goes through all active language servers and attempts to shut them down. - func stopAllServers() async throws { - for key in languageClients.keys { - try await stopServer(forLanguage: key.languageId, workspacePath: key.workspacePath) + func stopAllServers() async { + await withThrowingTaskGroup(of: Void.self) { group in + for (key, server) in languageClients { + group.addTask { + do { + try await server.shutdown() + } catch { + self.logger.error("Shutting down \(key.languageId.rawValue): Error \(error)") + throw error + } + } + } + } + languageClients.removeAll() + eventListeningTasks.forEach { (_, value) in + value.cancel() } + eventListeningTasks.removeAll() } }