Add a send method to InProcessSourceKitLSPClient and Connection in which the client specifies the request ID

This commit is contained in:
Alex Hoppen
2025-02-26 08:36:00 -08:00
parent 086f4796eb
commit db792c536f
6 changed files with 79 additions and 45 deletions

View File

@@ -14,6 +14,7 @@ import BuildSystemIntegration
public import Foundation
public import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
import SwiftExtensions
import TSCExtensions
@@ -124,11 +125,28 @@ public final class InProcessSourceKitLSPClient: Sendable {
_ request: R,
reply: @Sendable @escaping (LSPResult<R.Response>) -> Void
) -> RequestID {
let requestID = RequestID.number(Int(nextRequestID.fetchAndIncrement()))
let requestID = RequestID.string("sk-\(Int(nextRequestID.fetchAndIncrement()))")
server.handle(request, id: requestID, reply: reply)
return requestID
}
/// Send the request to `server` and return the request result via a completion handler.
///
/// The request ID must not start with `sk-` to avoid conflicting with the request IDs that are created by
/// `send(:reply:)`.
public func send<R: RequestType>(
_ request: R,
id: RequestID,
reply: @Sendable @escaping (LSPResult<R.Response>) -> Void
) {
if case .string(let string) = id {
if string.starts(with: "sk-") {
logger.fault("Manually specified request ID must not have reserved prefix 'sk-'")
}
}
server.handle(request, id: id, reply: reply)
}
/// Send the notification to `server`.
public func send(_ notification: some NotificationType) {
server.handle(notification)