Skip to content

Commit

Permalink
Merge pull request #1979 from bnbarham/fix-sendable
Browse files Browse the repository at this point in the history
Add sendable annotation to `userInfo` closure
  • Loading branch information
bnbarham authored Feb 17, 2025
2 parents 94ba7ea + 96247c0 commit e8e1972
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ public final class JSONRPCConnection: Connection {
decoder.userInfo[.messageRegistryKey] = messageRegistry

// Setup callback for response type.
decoder.userInfo[.responseTypeCallbackKey] = { (id: RequestID) -> ResponseType.Type? in
decoder.userInfo[.responseTypeCallbackKey] = { @Sendable (id: RequestID) -> ResponseType.Type? in
// `outstandingRequests` should never be mutated in this closure. Reading is fine as all of our other writes are
// guarded by `queue`, but `JSONDecoder` could (since this is sendable) invoke this concurrently.
guard let outstanding = self.outstandingRequests[id] else {
logger.error("Unknown request for \(id, privacy: .public)")
return nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/LanguageServerProtocolJSONRPC/MessageCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension CodingUserInfoKey {

extension JSONRPCMessage: Codable {

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

private enum CodingKeys: String, CodingKey {
case jsonrpc
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKTestSupport/CheckCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ package func checkDecoding<T: Codable & Equatable>(
package func checkCoding<T: Codable>(
_ value: T,
json: String,
userInfo: [CodingUserInfoKey: Any] = [:],
userInfo: [CodingUserInfoKey: any Sendable] = [:],
file: StaticString = #filePath,
line: UInt = #line,
body: (T) -> Void
Expand Down
10 changes: 6 additions & 4 deletions Tests/LanguageServerProtocolJSONRPCTests/CodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ final class CodingTests: XCTestCase {
return $0 == .string("unknown") ? nil : InitializeResult.self
}

var info = defaultCodingInfo as [CodingUserInfoKey: Any]
var info = defaultCodingInfo
info[CodingUserInfoKey.responseTypeCallbackKey] = responseTypeCallback

checkMessageDecodingError(
Expand Down Expand Up @@ -366,7 +366,9 @@ final class CodingTests: XCTestCase {
}
}

let defaultCodingInfo = [CodingUserInfoKey.messageRegistryKey: MessageRegistry.lspProtocol]
let defaultCodingInfo: [CodingUserInfoKey: any Sendable] = [
CodingUserInfoKey.messageRegistryKey: MessageRegistry.lspProtocol
]

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

var codingInfo = defaultCodingInfo as [CodingUserInfoKey: Any]
var codingInfo = defaultCodingInfo
codingInfo[.responseTypeCallbackKey] = callback

checkCoding(JSONRPCMessage.response(value, id: id), json: json, userInfo: codingInfo, file: file, line: line) {
Expand Down Expand Up @@ -462,7 +464,7 @@ private func checkMessageCoding(
private func checkMessageDecodingError(
_ expected: MessageDecodingError,
json: String,
userInfo: [CodingUserInfoKey: Any] = defaultCodingInfo,
userInfo: [CodingUserInfoKey: any Sendable] = defaultCodingInfo,
file: StaticString = #filePath,
line: UInt = #line
) {
Expand Down

0 comments on commit e8e1972

Please sign in to comment.