diff --git a/Sources/BuildServerIntegration/BuildServerManager.swift b/Sources/BuildServerIntegration/BuildServerManager.swift index 680e44a5..bc3040af 100644 --- a/Sources/BuildServerIntegration/BuildServerManager.swift +++ b/Sources/BuildServerIntegration/BuildServerManager.swift @@ -181,9 +181,10 @@ private enum BuildServerAdapter { if Task.isCancelled { return continuation.resume(throwing: CancellationError()) } - requestID.value = messageHandler.send(request) { response in + let id = messageHandler.send(request) { response in continuation.resume(with: response) } + requestID.withLock { $0 = id } if Task.isCancelled { // The task might have been cancelled after we checked `Task.isCancelled` above but before `requestID.value` // is set, we won't send a `CancelRequestNotification` from the `onCancel` handler. Send it from here. diff --git a/Sources/Diagnose/DiagnoseCommand.swift b/Sources/Diagnose/DiagnoseCommand.swift index 1d66f069..b1510acd 100644 --- a/Sources/Diagnose/DiagnoseCommand.swift +++ b/Sources/Diagnose/DiagnoseCommand.swift @@ -261,7 +261,7 @@ package struct DiagnoseCommand: AsyncParsableCommand { ) try process.launch() try await process.waitUntilExit() - processExited.value = true + processExited.withLock { $0 = true } #endif } diff --git a/Sources/DocumentationLanguageService/DocCReferenceResolutionService.swift b/Sources/DocumentationLanguageService/DocCReferenceResolutionService.swift index 35d2f07c..441466a2 100644 --- a/Sources/DocumentationLanguageService/DocCReferenceResolutionService.swift +++ b/Sources/DocumentationLanguageService/DocCReferenceResolutionService.swift @@ -34,7 +34,7 @@ final class DocCReferenceResolutionService: DocumentationService, Sendable { init() {} func addContext(_ context: DocCReferenceResolutionContext, withKey key: String) { - contextMap.value[key] = context + contextMap.withLock { $0[key] = context } } @discardableResult func removeContext(forKey key: String) -> DocCReferenceResolutionContext? { diff --git a/Sources/InProcessClient/InProcessSourceKitLSPClient.swift b/Sources/InProcessClient/InProcessSourceKitLSPClient.swift index ca0febb9..e4ab4b03 100644 --- a/Sources/InProcessClient/InProcessSourceKitLSPClient.swift +++ b/Sources/InProcessClient/InProcessSourceKitLSPClient.swift @@ -100,9 +100,10 @@ public final class InProcessSourceKitLSPClient: Sendable { // possible. return continuation.resume(throwing: CancellationError()) } - requestId.value = self.send(request) { + let id = self.send(request) { continuation.resume(with: $0) } + requestId.withLock { $0 = id } if Task.isCancelled, let requestId = requestId.takeValue() { // The task might have been cancelled after the above cancellation check but before `requestId` was assigned // a value. To cover that case, check for cancellation here again. Note that we won't cancel twice from here diff --git a/Sources/SKTestSupport/CustomBuildServerTestProject.swift b/Sources/SKTestSupport/CustomBuildServerTestProject.swift index 41494fec..4982cfd7 100644 --- a/Sources/SKTestSupport/CustomBuildServerTestProject.swift +++ b/Sources/SKTestSupport/CustomBuildServerTestProject.swift @@ -290,7 +290,7 @@ package final class CustomBuildServerTestProject XCTAssertNil(hooks.buildServerHooks.injectBuildServer) hooks.buildServerHooks.injectBuildServer = { [buildServerBox] projectRoot, connectionToSourceKitLSP in let buildServer = BuildServer(projectRoot: projectRoot, connectionToSourceKitLSP: connectionToSourceKitLSP) - buildServerBox.value = buildServer + buildServerBox.withLock { $0 = buildServer } return LocalConnection(receiverName: "TestBuildServer", handler: buildServer) } try await super.init( diff --git a/Sources/SKTestSupport/TestSourceKitLSPClient.swift b/Sources/SKTestSupport/TestSourceKitLSPClient.swift index cce45f5a..82031283 100644 --- a/Sources/SKTestSupport/TestSourceKitLSPClient.swift +++ b/Sources/SKTestSupport/TestSourceKitLSPClient.swift @@ -407,7 +407,7 @@ package final class TestSourceKitLSPClient: MessageHandler, Sendable { // Register a one-shot handler that records when the request arrives. let received = ThreadSafeBox(initialValue: false) self.handleSingleRequest { (_: R) in - received.value = true + received.withLock { $0 = true } return VoidResponse() } diff --git a/Sources/SemanticIndex/CheckedIndex.swift b/Sources/SemanticIndex/CheckedIndex.swift index 8c20d004..d223d515 100644 --- a/Sources/SemanticIndex/CheckedIndex.swift +++ b/Sources/SemanticIndex/CheckedIndex.swift @@ -356,7 +356,7 @@ package final actor UncheckedIndex: Sendable { package func close() { // IndexStoreDB writes the index to disk when the retain count of the `IndexStoreDB` object hits zero. We hope that // nobody else still has a reference to `IndexStoreDB` here. - _underlyingIndexStoreDB.value = nil + _underlyingIndexStoreDB.withLock { $0 = nil } } /// Update the set of output paths that should be considered visible in the project. For example, if a source file is diff --git a/Sources/SourceKitD/dlopen.swift b/Sources/SourceKitD/dlopen.swift index 17ace342..b0bc7aa4 100644 --- a/Sources/SourceKitD/dlopen.swift +++ b/Sources/SourceKitD/dlopen.swift @@ -80,7 +80,7 @@ package final class DLHandle: Sendable { /// The handle must not be used anymore after calling `leak`. package func leak() { - rawValue.value = nil + rawValue.withLock { $0 = nil } } } diff --git a/Sources/SwiftExtensions/AsyncUtils.swift b/Sources/SwiftExtensions/AsyncUtils.swift index e468a61b..11c01708 100644 --- a/Sources/SwiftExtensions/AsyncUtils.swift +++ b/Sources/SwiftExtensions/AsyncUtils.swift @@ -99,7 +99,7 @@ package func withTimeoutResult( let stream = AsyncThrowingStream, any Error> { continuation in Task { try await Task.sleep(for: timeout) - didHitTimeout.value = true + didHitTimeout.withLock { $0 = true } continuation.yield(.timedOut) } diff --git a/Sources/TSCExtensions/Process+Run.swift b/Sources/TSCExtensions/Process+Run.swift index bac00b95..31eb973f 100644 --- a/Sources/TSCExtensions/Process+Run.swift +++ b/Sources/TSCExtensions/Process+Run.swift @@ -35,7 +35,7 @@ extension Process { let hasExited = ThreadSafeBox(initialValue: false) return try await withTaskCancellationHandler { defer { - hasExited.value = true + hasExited.withLock { $0 = true } } return try await waitUntilExit() } onCancel: { diff --git a/Tests/BuildServerIntegrationTests/BuildServerManagerTests.swift b/Tests/BuildServerIntegrationTests/BuildServerManagerTests.swift index 63196fc3..4fc0a871 100644 --- a/Tests/BuildServerIntegrationTests/BuildServerManagerTests.swift +++ b/Tests/BuildServerIntegrationTests/BuildServerManagerTests.swift @@ -64,7 +64,7 @@ private func createBuildServerManager( kind: .injected({ projectRoot, connectionToSourceKitLSP in assert(testBuildServer.value == nil, "Build server injector hook can only create a single TestBuildServer") let buildServer = TestBuildServer(projectRoot: projectRoot, connectionToSourceKitLSP: connectionToSourceKitLSP) - testBuildServer.value = buildServer + testBuildServer.withLock { $0 = buildServer } return LocalConnection(receiverName: "TestBuildServer", handler: buildServer) }), projectRoot: dummyPath, diff --git a/Tests/BuildServerIntegrationTests/SwiftPMBuildServerTests.swift b/Tests/BuildServerIntegrationTests/SwiftPMBuildServerTests.swift index 721d4c1a..3a3fadd9 100644 --- a/Tests/BuildServerIntegrationTests/SwiftPMBuildServerTests.swift +++ b/Tests/BuildServerIntegrationTests/SwiftPMBuildServerTests.swift @@ -1334,11 +1334,11 @@ struct SwiftPMBuildServerTests { in: tempDir, reloadPackageDidStart: { if packageInitialized.value { - unexpectedReloadStarted.value = true + unexpectedReloadStarted.withLock { $0 = true } } } ) - packageInitialized.value = true + packageInitialized.withLock { $0 = true } // SwiftPM extracts the artifact bundle to: // /artifacts//// @@ -1388,11 +1388,11 @@ struct SwiftPMBuildServerTests { options: SourceKitLSPOptions(swiftPM: .init(scratchPath: try customScratch.filePath)), reloadPackageDidStart: { if packageInitialized.value { - unexpectedReloadStarted.value = true + unexpectedReloadStarted.withLock { $0 = true } } } ) - packageInitialized.value = true + packageInitialized.withLock { $0 = true } // With a custom scratch path, SwiftPM extracts to /artifacts/. // Simulate the delete-and-re-expand cycle for those paths. diff --git a/Tests/SemanticIndexTests/TaskSchedulerTests.swift b/Tests/SemanticIndexTests/TaskSchedulerTests.swift index a95852d6..da8f8191 100644 --- a/Tests/SemanticIndexTests/TaskSchedulerTests.swift +++ b/Tests/SemanticIndexTests/TaskSchedulerTests.swift @@ -261,7 +261,7 @@ final class TaskSchedulerTests: SourceKitLSPTestCase { return } - taskExecutedBefore.value = true + taskExecutedBefore.withLock { $0 = true } taskStartedExecuting.fulfill() diff --git a/Tests/SourceKitLSPTests/BackgroundIndexingTests.swift b/Tests/SourceKitLSPTests/BackgroundIndexingTests.swift index 251de87b..a3d54e6a 100644 --- a/Tests/SourceKitLSPTests/BackgroundIndexingTests.swift +++ b/Tests/SourceKitLSPTests/BackgroundIndexingTests.swift @@ -1392,7 +1392,7 @@ final class BackgroundIndexingTests: SourceKitLSPTestCase { hooks: testHooks, enableBackgroundIndexing: true ) - packageInitialized.value = true + packageInitialized.withLock { $0 = true } project.testClient.send( DidChangeWatchedFilesNotification(changes: [ FileEvent(uri: DocumentURI(project.scratchDirectory.appending(component: "random.swift")), type: .created) @@ -2186,7 +2186,7 @@ final class BackgroundIndexingTests: SourceKitLSPTestCase { return data.title == "Indexing" } ) - receivedReportProgressNotification.value = true + receivedReportProgressNotification.withLock { $0 = true } // Check that we receive an `end` notification _ = try await project.testClient.nextNotification( @@ -2255,7 +2255,7 @@ final class BackgroundIndexingTests: SourceKitLSPTestCase { // Ensure that changing `/private/tmp/.../test.c` only causes `/tmp/.../test.c` to be indexed, not // `/private/tmp/.../test.c`. - indexedFiles.value = [] + indexedFiles.withLock { $0 = [] } let testFileURL = try XCTUnwrap(project.uri(for: "test.c").fileURL?.realpath) try await "void y() {}".writeWithRetry(to: testFileURL) project.testClient.send( @@ -2603,7 +2603,7 @@ final class BackgroundIndexingTests: SourceKitLSPTestCase { let symbolsBeforeUpdate = try await project.testClient.send(WorkspaceSymbolsRequest(query: "myTestFu")) XCTAssertEqual(symbolsBeforeUpdate, []) - testSetupComplete.value = true + testSetupComplete.withLock { $0 = true } try await project.changeFileOnDisk( "Test.swift", newMarkedContents: """ diff --git a/Tests/SourceKitLSPTests/ClangdTests.swift b/Tests/SourceKitLSPTests/ClangdTests.swift index 239167c9..16e12d82 100644 --- a/Tests/SourceKitLSPTests/ClangdTests.swift +++ b/Tests/SourceKitLSPTests/ClangdTests.swift @@ -162,7 +162,7 @@ final class ClangdTests: SourceKitLSPTestCase { let clangdServer = try await unwrap(testClient.primaryLanguageService(for: uri)) await clangdServer.addStateChangeHandler { oldState, newState in if oldState == .connectionInterrupted, newState == .connected { - clangdRestarted.value = true + clangdRestarted.withLock { $0 = true } clangdRestartedExpectation.fulfill() } } diff --git a/Tests/SourceKitLSPTests/ExecuteCommandTests.swift b/Tests/SourceKitLSPTests/ExecuteCommandTests.swift index e2f35f2c..d36b0a9c 100644 --- a/Tests/SourceKitLSPTests/ExecuteCommandTests.swift +++ b/Tests/SourceKitLSPTests/ExecuteCommandTests.swift @@ -53,8 +53,8 @@ final class ExecuteCommandTests: SourceKitLSPTestCase { let applyEditWorkspaceEdit = ThreadSafeBox(initialValue: nil) testClient.handleSingleRequest { (req: ApplyEditRequest) -> ApplyEditResponse in - applyEditTitle.value = req.label - applyEditWorkspaceEdit.value = req.edit + applyEditTitle.withLock { $0 = req.label } + applyEditWorkspaceEdit.withLock { $0 = req.edit } expectation.fulfill() return ApplyEditResponse(applied: true, failureReason: nil) @@ -118,8 +118,8 @@ final class ExecuteCommandTests: SourceKitLSPTestCase { let applyEditWorkspaceEdit = ThreadSafeBox(initialValue: nil) testClient.handleSingleRequest { (req: ApplyEditRequest) -> ApplyEditResponse in - applyEditTitle.value = req.label - applyEditWorkspaceEdit.value = req.edit + applyEditTitle.withLock { $0 = req.label } + applyEditWorkspaceEdit.withLock { $0 = req.edit } expectation.fulfill() return ApplyEditResponse(applied: true, failureReason: nil) diff --git a/Tests/SourceKitLSPTests/ExpandMacroTests.swift b/Tests/SourceKitLSPTests/ExpandMacroTests.swift index c8575155..5b03814c 100644 --- a/Tests/SourceKitLSPTests/ExpandMacroTests.swift +++ b/Tests/SourceKitLSPTests/ExpandMacroTests.swift @@ -91,7 +91,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let peekDocumentsRequestURIs = ThreadSafeBox<[DocumentURI]?>(initialValue: nil) project.testClient.handleSingleRequest { (req: PeekDocumentsRequest) in - peekDocumentsRequestURIs.value = req.locations + peekDocumentsRequestURIs.withLock { $0 = req.locations } expectation.fulfill() return PeekDocumentsResponse(success: true) } @@ -130,7 +130,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let showDocumentRequestURI = ThreadSafeBox(initialValue: nil) project.testClient.handleSingleRequest { (req: ShowDocumentRequest) in - showDocumentRequestURI.value = req.uri + showDocumentRequestURI.withLock { $0 = req.uri } expectation.fulfill() return ShowDocumentResponse(success: true) } @@ -244,7 +244,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let peekDocumentsRequestURIs = ThreadSafeBox<[DocumentURI]?>(initialValue: nil) project.testClient.handleSingleRequest { (req: PeekDocumentsRequest) in - peekDocumentsRequestURIs.value = req.locations + peekDocumentsRequestURIs.withLock { $0 = req.locations } expectation.fulfill() return PeekDocumentsResponse(success: true) } @@ -291,7 +291,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let showDocumentRequestURI = ThreadSafeBox(initialValue: nil) project.testClient.handleSingleRequest { (req: ShowDocumentRequest) in - showDocumentRequestURI.value = req.uri + showDocumentRequestURI.withLock { $0 = req.uri } expectation.fulfill() return ShowDocumentResponse(success: true) } @@ -388,7 +388,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let outerPeekDocumentsRequestURIs = ThreadSafeBox<[DocumentURI]?>(initialValue: nil) project.testClient.handleSingleRequest { (req: PeekDocumentsRequest) in - outerPeekDocumentsRequestURIs.value = req.locations + outerPeekDocumentsRequestURIs.withLock { $0 = req.locations } outerPeekDocumentRequestReceived.fulfill() return PeekDocumentsResponse(success: true) } @@ -423,7 +423,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let intermediatePeekDocumentsRequestURIs = ThreadSafeBox<[DocumentURI]?>(initialValue: nil) project.testClient.handleSingleRequest { (req: PeekDocumentsRequest) in - intermediatePeekDocumentsRequestURIs.value = req.locations + intermediatePeekDocumentsRequestURIs.withLock { $0 = req.locations } intermediatePeekDocumentRequestReceived.fulfill() return PeekDocumentsResponse(success: true) } @@ -460,7 +460,7 @@ final class ExpandMacroTests: SourceKitLSPTestCase { let innerPeekDocumentsRequestURIs = ThreadSafeBox<[DocumentURI]?>(initialValue: nil) project.testClient.handleSingleRequest { (req: PeekDocumentsRequest) in - innerPeekDocumentsRequestURIs.value = req.locations + innerPeekDocumentsRequestURIs.withLock { $0 = req.locations } innerPeekDocumentRequestReceived.fulfill() return PeekDocumentsResponse(success: true) } diff --git a/Tests/SourceKitLSPTests/SourcekitdCoreInjectorTests.swift b/Tests/SourceKitLSPTests/SourcekitdCoreInjectorTests.swift index 33a7362b..83a6b308 100644 --- a/Tests/SourceKitLSPTests/SourcekitdCoreInjectorTests.swift +++ b/Tests/SourceKitLSPTests/SourcekitdCoreInjectorTests.swift @@ -48,7 +48,7 @@ final class SourcekitdCoreInjectorTests: SourceKitLSPTestCase { let testClient = try await TestSourceKitLSPClient( hooks: Hooks(sourcekitdCoreInjector: { toolchainURL in injectorCallCount.withLock { $0 += 1 } - capturedToolchainURL.value = toolchainURL + capturedToolchainURL.withLock { $0 = toolchainURL } return injectedCore }) ) diff --git a/Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift b/Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift index 778af4b0..e83b9494 100644 --- a/Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift +++ b/Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift @@ -136,7 +136,7 @@ final class WorkspaceTestDiscoveryTests: SourceKitLSPTestCase { enableBackgroundIndexing: true ) - initialIndexingFinished.value = true + initialIndexingFinished.withLock { $0 = true } let myTestsUri = try project.uri(for: "MyTests.swift") diff --git a/Tests/SourceKitLSPTests/WorkspaceTests.swift b/Tests/SourceKitLSPTests/WorkspaceTests.swift index 3ba03678..4f411583 100644 --- a/Tests/SourceKitLSPTests/WorkspaceTests.swift +++ b/Tests/SourceKitLSPTests/WorkspaceTests.swift @@ -1161,7 +1161,7 @@ final class WorkspaceTests: SourceKitLSPTestCase { project.testClient.send(DidChangeWatchedFilesNotification(changes: [FileEvent(uri: baseLibUri, type: .changed)])) // Ensure that we handle the `DidChangeWatchedFilesNotification`. try await project.testClient.send(SynchronizeRequest()) - didChangeBaseLib.value = true + didChangeBaseLib.withLock { $0 = true } project.testClient.send( DidChangeActiveDocumentNotification(textDocument: TextDocumentIdentifier(libBUri)) @@ -1280,7 +1280,7 @@ final class WorkspaceTests: SourceKitLSPTestCase { project.testClient.send(DidChangeWatchedFilesNotification(changes: [FileEvent(uri: baseLibUri, type: .changed)])) // Ensure that we handle the `DidChangeWatchedFilesNotification`. try await project.testClient.send(SynchronizeRequest()) - didChangeBaseLib.value = true + didChangeBaseLib.withLock { $0 = true } let triggerPrepare = try await project.testClient.send( SourceKitOptionsRequest(