Skip to content

Commit 4b7c16f

Browse files
committed
Inherit actor isolation of closure passed to orLog
This allows us to express that `body` will run on the same actor isolation domain as the caller of `orLog`, which effectively makes `orLog` usable from actors again.
1 parent 7ee04d1 commit 4b7c16f

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Sources/LSPLogging/OrLog.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import os
1515
#endif
1616

17-
public func logError(prefix: String, error: Error, level: LogLevel = .error) {
17+
private func logError(prefix: String, error: Error, level: LogLevel = .error) {
1818
logger.log(
1919
level: level,
2020
"\(prefix, privacy: .public)\(prefix.isEmpty ? "" : ": ", privacy: .public)\(error.forLogging)"
@@ -41,7 +41,7 @@ public func orLog<R>(
4141
public func orLog<R>(
4242
_ prefix: String,
4343
level: LogLevel = .error,
44-
_ block: () async throws -> R?
44+
@_inheritActorContext _ block: @Sendable () async throws -> R?
4545
) async -> R? {
4646
do {
4747
return try await block()

Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,9 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
363363
public func filesDidChange(_ events: [FileEvent]) async {
364364
if events.contains(where: { self.fileEventShouldTriggerPackageReload(event: $0) }) {
365365
logger.log("Reloading package because of file change")
366-
do {
366+
await orLog("Reloading package") {
367367
// TODO: It should not be necessary to reload the entire package just to get build settings for one file.
368368
try await self.reloadPackage()
369-
} catch {
370-
logError(prefix: "Reloading package", error: error)
371369
}
372370
}
373371
}

0 commit comments

Comments
 (0)