Skip to content

Commit cc5a83b

Browse files
committed
Wait for documents to be re-opened before setting the clangd status to be connected again
1 parent 7e6d39b commit cc5a83b

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

Sources/SourceKitLSP/Clang/ClangLanguageServer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
9494
private let workspace: WeakWorkspace
9595

9696
/// A callback with which `ClangLanguageServer` can request its owner to reopen all documents in case it has crashed.
97-
private let reopenDocuments: (ToolchainLanguageServer) -> Void
97+
private let reopenDocuments: (ToolchainLanguageServer) async -> Void
9898

9999
/// The documents that have been opened and which language they have been
100100
/// opened with.
@@ -114,7 +114,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
114114
toolchain: Toolchain,
115115
options: SourceKitServer.Options,
116116
workspace: Workspace,
117-
reopenDocuments: @escaping (ToolchainLanguageServer) -> Void,
117+
reopenDocuments: @escaping (ToolchainLanguageServer) async -> Void,
118118
workspaceForDocument: @escaping (DocumentURI) async -> Workspace?
119119
) async throws {
120120
guard let clangdPath = toolchain.clangd else {
@@ -245,7 +245,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
245245
// But since SourceKitServer more or less ignores them right now anyway, this should be fine for now.
246246
_ = try self.initializeSync(initializeRequest)
247247
self.clientInitialized(InitializedNotification())
248-
self.reopenDocuments(self)
248+
await self.reopenDocuments(self)
249249
self.state = .connected
250250
} catch {
251251
log("Failed to restart clangd after a crash.", level: .error)

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,7 @@ public actor SourceKitServer {
406406
client: self,
407407
in: workspace,
408408
reopenDocuments: { [weak self] toolchainLanguageServer in
409-
guard let self else { return }
410-
Task {
411-
await self.reopenDocuments(for: toolchainLanguageServer)
412-
}
409+
await self?.reopenDocuments(for: toolchainLanguageServer)
413410
},
414411
workspaceForDocument: { [weak self] document in
415412
guard let self else { return nil }
@@ -2008,7 +2005,7 @@ func languageService(
20082005
options: SourceKitServer.Options,
20092006
client: MessageHandler,
20102007
in workspace: Workspace,
2011-
reopenDocuments: @escaping (ToolchainLanguageServer) -> Void,
2008+
reopenDocuments: @escaping (ToolchainLanguageServer) async -> Void,
20122009
workspaceForDocument: @escaping (DocumentURI) async -> Workspace?
20132010
) async throws -> ToolchainLanguageServer? {
20142011
let connectionToClient = LocalConnection()

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public actor SwiftLanguageServer: ToolchainLanguageServer {
150150
private var stateChangeHandlers: [(_ oldState: LanguageServerState, _ newState: LanguageServerState) -> Void] = []
151151

152152
/// A callback with which `SwiftLanguageServer` can request its owner to reopen all documents in case it has crashed.
153-
private let reopenDocuments: (ToolchainLanguageServer) -> Void
153+
private let reopenDocuments: (ToolchainLanguageServer) async -> Void
154154

155155
/// Get the workspace that the document with the given URI belongs to.
156156
///
@@ -166,7 +166,7 @@ public actor SwiftLanguageServer: ToolchainLanguageServer {
166166
toolchain: Toolchain,
167167
options: SourceKitServer.Options,
168168
workspace: Workspace,
169-
reopenDocuments: @escaping (ToolchainLanguageServer) -> Void,
169+
reopenDocuments: @escaping (ToolchainLanguageServer) async -> Void,
170170
workspaceForDocument: @escaping (DocumentURI) async -> Workspace?
171171
) throws {
172172
guard let sourcekitd = toolchain.sourcekitd else { return nil }
@@ -1523,7 +1523,7 @@ extension SwiftLanguageServer: SKDNotificationHandler {
15231523
self.state = .semanticFunctionalityDisabled
15241524

15251525
// Ask our parent to re-open all of our documents.
1526-
self.reopenDocuments(self)
1526+
await self.reopenDocuments(self)
15271527
}
15281528

15291529
if case .connectionInterrupted = notification.error {

Sources/SourceKitLSP/ToolchainLanguageServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public protocol ToolchainLanguageServer: AnyObject {
3434
toolchain: Toolchain,
3535
options: SourceKitServer.Options,
3636
workspace: Workspace,
37-
reopenDocuments: @escaping (ToolchainLanguageServer) -> Void,
37+
reopenDocuments: @escaping (ToolchainLanguageServer) async -> Void,
3838
workspaceForDocument: @escaping (DocumentURI) async -> Workspace?
3939
) async throws
4040

0 commit comments

Comments
 (0)