@@ -14,6 +14,7 @@ import BuildSystemIntegration
14
14
public import Foundation
15
15
public import LanguageServerProtocol
16
16
import LanguageServerProtocolExtensions
17
+ import SKLogging
17
18
import SwiftExtensions
18
19
import TSCExtensions
19
20
@@ -35,6 +36,8 @@ public final class InProcessSourceKitLSPClient: Sendable {
35
36
36
37
private let nextRequestID = AtomicUInt32 ( initialValue: 0 )
37
38
39
+ private let requestIDPrefix = " inproc- "
40
+
38
41
public convenience init (
39
42
toolchainPath: URL ? ,
40
43
capabilities: ClientCapabilities = ClientCapabilities ( ) ,
@@ -124,11 +127,35 @@ public final class InProcessSourceKitLSPClient: Sendable {
124
127
_ request: R ,
125
128
reply: @Sendable @escaping ( LSPResult < R . Response > ) -> Void
126
129
) -> RequestID {
127
- let requestID = RequestID . number ( Int ( nextRequestID. fetchAndIncrement ( ) ) )
130
+ let requestID = RequestID . string ( " \( requestIDPrefix ) \( Int ( nextRequestID. fetchAndIncrement ( ) ) ) " )
128
131
server. handle ( request, id: requestID, reply: reply)
129
132
return requestID
130
133
}
131
134
135
+ /// Send the request to `server` and return the request result via a completion handler.
136
+ ///
137
+ /// The request ID must not start with `inproc-` to avoid conflicting with the request IDs that are created by
138
+ /// `send(:reply:)`.
139
+ public func send< R: RequestType > (
140
+ _ request: R ,
141
+ requestID: RequestID ,
142
+ reply: @Sendable @escaping ( LSPResult < R . Response > ) -> Void
143
+ ) {
144
+ #if DEBUG
145
+ if case . string( let string) = requestID {
146
+ if string. starts ( with: requestIDPrefix) {
147
+ logger. fault (
148
+ """
149
+ Manually specified request ID to InProcessSoruceKitLSPClient has reserved prefix \
150
+ ' \( self . requestIDPrefix, privacy: . public) '
151
+ """
152
+ )
153
+ }
154
+ }
155
+ #endif
156
+ server. handle ( request, id: requestID, reply: reply)
157
+ }
158
+
132
159
/// Send the notification to `server`.
133
160
public func send( _ notification: some NotificationType ) {
134
161
server. handle ( notification)
0 commit comments