Skip to content

Commit e8e1972

Browse files
authored
Merge pull request #1979 from bnbarham/fix-sendable
Add sendable annotation to `userInfo` closure
2 parents 94ba7ea + 96247c0 commit e8e1972

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Sources/LanguageServerProtocolJSONRPC/JSONRPCConnection.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ public final class JSONRPCConnection: Connection {
367367
decoder.userInfo[.messageRegistryKey] = messageRegistry
368368

369369
// Setup callback for response type.
370-
decoder.userInfo[.responseTypeCallbackKey] = { (id: RequestID) -> ResponseType.Type? in
370+
decoder.userInfo[.responseTypeCallbackKey] = { @Sendable (id: RequestID) -> ResponseType.Type? in
371+
// `outstandingRequests` should never be mutated in this closure. Reading is fine as all of our other writes are
372+
// guarded by `queue`, but `JSONDecoder` could (since this is sendable) invoke this concurrently.
371373
guard let outstanding = self.outstandingRequests[id] else {
372374
logger.error("Unknown request for \(id, privacy: .public)")
373375
return nil

Sources/LanguageServerProtocolJSONRPC/MessageCoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension CodingUserInfoKey {
3434

3535
extension JSONRPCMessage: Codable {
3636

37-
public typealias ResponseTypeCallback = (RequestID) -> ResponseType.Type?
37+
public typealias ResponseTypeCallback = @Sendable (RequestID) -> ResponseType.Type?
3838

3939
private enum CodingKeys: String, CodingKey {
4040
case jsonrpc

Sources/SKTestSupport/CheckCoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ package func checkDecoding<T: Codable & Equatable>(
9595
package func checkCoding<T: Codable>(
9696
_ value: T,
9797
json: String,
98-
userInfo: [CodingUserInfoKey: Any] = [:],
98+
userInfo: [CodingUserInfoKey: any Sendable] = [:],
9999
file: StaticString = #filePath,
100100
line: UInt = #line,
101101
body: (T) -> Void

Tests/LanguageServerProtocolJSONRPCTests/CodingTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ final class CodingTests: XCTestCase {
283283
return $0 == .string("unknown") ? nil : InitializeResult.self
284284
}
285285

286-
var info = defaultCodingInfo as [CodingUserInfoKey: Any]
286+
var info = defaultCodingInfo
287287
info[CodingUserInfoKey.responseTypeCallbackKey] = responseTypeCallback
288288

289289
checkMessageDecodingError(
@@ -366,7 +366,9 @@ final class CodingTests: XCTestCase {
366366
}
367367
}
368368

369-
let defaultCodingInfo = [CodingUserInfoKey.messageRegistryKey: MessageRegistry.lspProtocol]
369+
let defaultCodingInfo: [CodingUserInfoKey: any Sendable] = [
370+
CodingUserInfoKey.messageRegistryKey: MessageRegistry.lspProtocol
371+
]
370372

371373
private func checkMessageCoding<Request: RequestType & Equatable>(
372374
_ value: Request,
@@ -417,7 +419,7 @@ private func checkMessageCoding<Response: ResponseType & Equatable>(
417419
return $0 == .string("unknown") ? nil : Response.self
418420
}
419421

420-
var codingInfo = defaultCodingInfo as [CodingUserInfoKey: Any]
422+
var codingInfo = defaultCodingInfo
421423
codingInfo[.responseTypeCallbackKey] = callback
422424

423425
checkCoding(JSONRPCMessage.response(value, id: id), json: json, userInfo: codingInfo, file: file, line: line) {
@@ -462,7 +464,7 @@ private func checkMessageCoding(
462464
private func checkMessageDecodingError(
463465
_ expected: MessageDecodingError,
464466
json: String,
465-
userInfo: [CodingUserInfoKey: Any] = defaultCodingInfo,
467+
userInfo: [CodingUserInfoKey: any Sendable] = defaultCodingInfo,
466468
file: StaticString = #filePath,
467469
line: UInt = #line
468470
) {

0 commit comments

Comments
 (0)