Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CodeEdit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
TaskNotificationHandler.postTask(action: .create, model: task)
}

try await withTimeout(
duration: .seconds(5.0),
try? await withTimeout(
duration: .seconds(2.0),
onTimeout: {
// Stop-gap measure to ensure we don't hang on CMD-Q
await self.lspService.killAllServers()
Expand Down
4 changes: 1 addition & 3 deletions CodeEdit/Features/LSP/LanguageServer/LanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ class LanguageServer<DocumentType: LanguageServerDocument> {
/// Shuts down the language server and exits it.
public func shutdown() async throws {
self.logger.info("Shutting down language server")
try await withTimeout(duration: .seconds(1.0)) {
try await self.lspInstance.shutdownAndExit()
}
try await self.lspInstance.shutdownAndExit()
}
}

Expand Down
12 changes: 8 additions & 4 deletions CodeEdit/Utils/withTimeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public func withTimeout<R>(
}
// Start timeout child task.
group.addTask {
if .now > deadline {
if .now < deadline {
try await Task.sleep(until: deadline) // sleep until the deadline
}
try Task.checkCancellation()
Expand All @@ -39,8 +39,12 @@ public func withTimeout<R>(
throw TimedOutError()
}
// First finished child task wins, cancel the other task.
let result = try await group.next()!
group.cancelAll()
return result
defer { group.cancelAll() }
do {
let result = try await group.next()!
return result
} catch {
throw error
}
}
}
Loading