Skip to content

Commit 0d90601

Browse files
committed
Add Sendable annotations to LSPLogging
1 parent fa54ef1 commit 0d90601

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ let package = Package(
138138
.product(name: "Crypto", package: "swift-crypto")
139139
],
140140
exclude: ["CMakeLists.txt"],
141-
swiftSettings: lspLoggingSwiftSettings
141+
swiftSettings: lspLoggingSwiftSettings + [.enableExperimentalFeature("StrictConcurrency")]
142142
),
143143

144144
.testTarget(

Sources/LSPLogging/NonDarwinLogging.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public enum LogConfig {
4545
///
4646
/// For documentation of the different log levels see
4747
/// https://developer.apple.com/documentation/os/oslogtype.
48-
public enum NonDarwinLogLevel: Comparable, CustomStringConvertible {
48+
public enum NonDarwinLogLevel: Comparable, CustomStringConvertible, Sendable {
4949
case debug
5050
case info
5151
case `default`
@@ -102,7 +102,7 @@ public enum NonDarwinLogLevel: Comparable, CustomStringConvertible {
102102
///
103103
/// For documentation of the different privacy levels see
104104
/// https://developer.apple.com/documentation/os/oslogprivacy.
105-
public enum NonDarwinLogPrivacy: Comparable {
105+
public enum NonDarwinLogPrivacy: Comparable, Sendable {
106106
case `public`
107107
case `private`
108108
case sensitive
@@ -132,16 +132,16 @@ public enum NonDarwinLogPrivacy: Comparable {
132132
/// sourcekit-lsp.
133133
///
134134
/// This is used on platforms that don't have OSLog.
135-
public struct NonDarwinLogInterpolation: StringInterpolationProtocol {
136-
private enum LogPiece {
135+
public struct NonDarwinLogInterpolation: StringInterpolationProtocol, Sendable {
136+
private enum LogPiece: Sendable {
137137
/// A segment of the log message that will always be displayed.
138138
case string(String)
139139

140140
/// A segment of the log message that might need to be redacted if the
141141
/// privacy level is lower than `privacy`.
142142
case possiblyRedacted(
143-
description: () -> String,
144-
redactedDescription: () -> String,
143+
description: @Sendable () -> String,
144+
redactedDescription: @Sendable () -> String,
145145
privacy: NonDarwinLogPrivacy
146146
)
147147
}
@@ -158,8 +158,8 @@ public struct NonDarwinLogInterpolation: StringInterpolationProtocol {
158158
}
159159

160160
private mutating func append(
161-
description: @autoclosure @escaping () -> String,
162-
redactedDescription: @autoclosure @escaping () -> String,
161+
description: @autoclosure @escaping @Sendable () -> String,
162+
redactedDescription: @autoclosure @escaping @Sendable () -> String,
163163
privacy: NonDarwinLogPrivacy
164164
) {
165165
if privacy == .public {
@@ -181,13 +181,15 @@ public struct NonDarwinLogInterpolation: StringInterpolationProtocol {
181181
}
182182

183183
@_disfavoredOverload // Prefer to use the StaticString overload when possible.
184-
public mutating func appendInterpolation(_ message: CustomStringConvertible, privacy: NonDarwinLogPrivacy = .private)
185-
{
184+
public mutating func appendInterpolation(
185+
_ message: some CustomStringConvertible & Sendable,
186+
privacy: NonDarwinLogPrivacy = .private
187+
) {
186188
append(description: message.description, redactedDescription: "<private>", privacy: privacy)
187189
}
188190

189191
public mutating func appendInterpolation(
190-
_ message: CustomLogStringConvertibleWrapper,
192+
_ message: some CustomLogStringConvertibleWrapper & Sendable,
191193
privacy: NonDarwinLogPrivacy = .private
192194
) {
193195
append(description: message.description, redactedDescription: message.redactedDescription, privacy: privacy)
@@ -198,7 +200,7 @@ public struct NonDarwinLogInterpolation: StringInterpolationProtocol {
198200
}
199201

200202
/// Builds the string that represents the log message, masking all interpolation
201-
/// segments whose privacy level is greater thatn `logPrivacyLevel`.
203+
/// segments whose privacy level is greater that `logPrivacyLevel`.
202204
fileprivate func string(for logPrivacyLevel: NonDarwinLogPrivacy) -> String {
203205
var result = ""
204206
for piece in pieces {
@@ -221,7 +223,7 @@ public struct NonDarwinLogInterpolation: StringInterpolationProtocol {
221223
/// sourcekit-lsp.
222224
///
223225
/// This is used on platforms that don't have OSLog.
224-
public struct NonDarwinLogMessage: ExpressibleByStringInterpolation, ExpressibleByStringLiteral {
226+
public struct NonDarwinLogMessage: ExpressibleByStringInterpolation, ExpressibleByStringLiteral, Sendable {
225227
fileprivate let value: NonDarwinLogInterpolation
226228

227229
public init(stringInterpolation: NonDarwinLogInterpolation) {
@@ -257,12 +259,12 @@ private let loggingQueue: DispatchQueue = DispatchQueue(label: "loggingQueue", q
257259
///
258260
/// This logger is used to log messages to stderr on platforms where OSLog is
259261
/// not available.
260-
public struct NonDarwinLogger {
262+
public struct NonDarwinLogger: Sendable {
261263
private let subsystem: String
262264
private let category: String
263265
private let logLevel: NonDarwinLogLevel
264266
private let privacyLevel: NonDarwinLogPrivacy
265-
private let logHandler: (String) -> Void
267+
private let logHandler: @Sendable (String) -> Void
266268

267269
/// - Parameters:
268270
/// - subsystem: See os.Logger
@@ -277,7 +279,7 @@ public struct NonDarwinLogger {
277279
category: String,
278280
logLevel: NonDarwinLogLevel? = nil,
279281
privacyLevel: NonDarwinLogPrivacy? = nil,
280-
logHandler: @escaping (String) -> Void = { fputs($0 + "\n", stderr) }
282+
logHandler: @escaping @Sendable (String) -> Void = { fputs($0 + "\n", stderr) }
281283
) {
282284
self.subsystem = subsystem
283285
self.category = category
@@ -292,7 +294,7 @@ public struct NonDarwinLogger {
292294
/// program to finish as quickly as possible.
293295
public func log(
294296
level: NonDarwinLogLevel,
295-
_ message: @autoclosure @escaping () -> NonDarwinLogMessage
297+
_ message: @autoclosure @escaping @Sendable () -> NonDarwinLogMessage
296298
) {
297299
guard level >= self.logLevel else { return }
298300
let date = Date()

0 commit comments

Comments
 (0)