Skip to content

Commit

Permalink
Use LSPService Shutdown Method
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Sep 24, 2024
1 parent 38b0d39 commit d585370
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
12 changes: 1 addition & 11 deletions CodeEdit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
20 changes: 17 additions & 3 deletions CodeEdit/Features/LSP/Service/LSPService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit d585370

Please sign in to comment.