Skip to content

Commit 8d71b31

Browse files
authored
Merge pull request #946 from ahoppen/ahoppen/remove-connection-sendsync
Remove `Connection.sendSync`
2 parents 57fc161 + baa450a commit 8d71b31

File tree

6 files changed

+14
-30
lines changed

6 files changed

+14
-30
lines changed

Sources/LanguageServerProtocol/Connection.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,13 @@ import SKSupport
1717
public protocol Connection: AnyObject {
1818

1919
/// Send a notification without a reply.
20-
func send<Notification>(_: Notification) where Notification: NotificationType
20+
func send(_ notification: some NotificationType)
2121

2222
/// Send a request and (asynchronously) receive a reply.
2323
func send<Request: RequestType>(
2424
_: Request,
2525
reply: @escaping (LSPResult<Request.Response>) -> Void
2626
) -> RequestID
27-
28-
/// Send a request synchronously. **Use wisely**.
29-
func sendSync<Request>(_: Request) throws -> Request.Response where Request: RequestType
30-
}
31-
32-
extension Connection {
33-
public func sendSync<Request>(_ request: Request) throws -> Request.Response where Request: RequestType {
34-
var result: LSPResult<Request.Response>? = nil
35-
let semaphore = DispatchSemaphore(value: 0)
36-
_ = send(request) { _result in
37-
result = _result
38-
semaphore.signal()
39-
}
40-
semaphore.wait()
41-
return try result!.get()
42-
}
4327
}
4428

4529
/// An abstract message handler, such as a language server or client.

Sources/SKCore/BuildServerBuildSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public actor BuildServerBuildSystem: MessageHandler {
102102
self.buildFolder = buildFolder
103103
self.projectRoot = projectRoot
104104
self.serverConfig = config
105-
try self.initializeBuildServer()
105+
try await self.initializeBuildServer()
106106
}
107107

108108
/// Creates a build system using the Build Server Protocol config.
@@ -134,7 +134,7 @@ public actor BuildServerBuildSystem: MessageHandler {
134134
}
135135
}
136136

137-
private func initializeBuildServer() throws {
137+
private func initializeBuildServer() async throws {
138138
var serverPath = try AbsolutePath(validating: serverConfig.argv[0], relativeTo: projectRoot)
139139
var flags = Array(serverConfig.argv[1...])
140140
if serverPath.suffix == ".py" {
@@ -172,7 +172,7 @@ public actor BuildServerBuildSystem: MessageHandler {
172172
)
173173

174174
let buildServer = try makeJSONRPCBuildServer(client: self, serverPath: serverPath, serverFlags: flags)
175-
let response = try buildServer.sendSync(initializeRequest)
175+
let response = try await buildServer.send(initializeRequest)
176176
buildServer.send(InitializedBuildNotification())
177177
logger.log("initialized build server \(response.displayName)")
178178

Sources/SourceKitLSP/Clang/ClangLanguageServer.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
127127
self.workspace = WeakWorkspace(workspace)
128128
self.state = .connected
129129
self.sourceKitServer = sourceKitServer
130-
try startClangdProcesss()
130+
try startClangdProcess()
131131
}
132132

133133
private func buildSettings(for document: DocumentURI) async -> ClangBuildSettings? {
@@ -172,7 +172,7 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
172172
}
173173

174174
/// Start the `clangd` process, either on creation of the `ClangLanguageServerShim` or after `clangd` has crashed.
175-
private func startClangdProcesss() throws {
175+
private func startClangdProcess() throws {
176176
// Since we are starting a new clangd process, reset the list of open document
177177
openDocuments = [:]
178178

@@ -248,11 +248,11 @@ actor ClangLanguageServerShim: ToolchainLanguageServer, MessageHandler {
248248
try await Task.sleep(nanoseconds: UInt64(restartDelay) * 1_000_000_000)
249249
self.clangRestartScheduled = false
250250
do {
251-
try self.startClangdProcesss()
252-
// FIXME: We assume that clangd will return the same capabilites after restarting.
251+
try self.startClangdProcess()
252+
// FIXME: We assume that clangd will return the same capabilities after restarting.
253253
// Theoretically they could have changed and we would need to inform SourceKitServer about them.
254254
// But since SourceKitServer more or less ignores them right now anyway, this should be fine for now.
255-
_ = try self.initializeSync(initializeRequest)
255+
_ = try await self.initialize(initializeRequest)
256256
self.clientInitialized(InitializedNotification())
257257
if let sourceKitServer {
258258
await sourceKitServer.reopenDocuments(for: self)
@@ -393,11 +393,11 @@ extension ClangLanguageServerShim {
393393

394394
extension ClangLanguageServerShim {
395395

396-
func initializeSync(_ initialize: InitializeRequest) throws -> InitializeResult {
396+
func initialize(_ initialize: InitializeRequest) async throws -> InitializeResult {
397397
// Store the initialize request so we can replay it in case clangd crashes
398398
self.initializeRequest = initialize
399399

400-
let result = try clangd.sendSync(initialize)
400+
let result = try await clangd.send(initialize)
401401
self.capabilities = result.capabilities
402402
return result
403403
}

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public actor SourceKitServer {
516516
}
517517

518518
let pid = Int(ProcessInfo.processInfo.processIdentifier)
519-
let resp = try await service.initializeSync(
519+
let resp = try await service.initialize(
520520
InitializeRequest(
521521
processId: pid,
522522
rootPath: nil,

Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public actor SwiftLanguageServer: ToolchainLanguageServer {
196196

197197
extension SwiftLanguageServer {
198198

199-
public func initializeSync(_ initialize: InitializeRequest) throws -> InitializeResult {
199+
public func initialize(_ initialize: InitializeRequest) throws -> InitializeResult {
200200
sourcekitd.addNotificationHandler(self)
201201

202202
return InitializeResult(

Sources/SourceKitLSP/ToolchainLanguageServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public protocol ToolchainLanguageServer: AnyObject {
4343

4444
// MARK: - Lifetime
4545

46-
func initializeSync(_ initialize: InitializeRequest) async throws -> InitializeResult
46+
func initialize(_ initialize: InitializeRequest) async throws -> InitializeResult
4747
func clientInitialized(_ initialized: InitializedNotification) async
4848

4949
/// Shut the server down and return once the server has finished shutting down

0 commit comments

Comments
 (0)