From 6b630e16a00b293191d0c430e574b53d8d4410f0 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Mon, 30 Jun 2025 12:17:15 -0700 Subject: [PATCH 1/2] Allow overriding SwiftPM's build directory with background indexing If `scratchPath` is explicitly set, use it over the separate `index-build` arena even when background indexing is enabled. --- Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift | 8 ++++---- Sources/InProcessClient/InProcessSourceKitLSPClient.swift | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift b/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift index 96d9c3e4c..5eaf798a5 100644 --- a/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift +++ b/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift @@ -203,7 +203,7 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem { throw Error.cannotDetermineHostToolchain } - var absProjectRoot = try AbsolutePath(validating: projectRoot.filePath) + let absProjectRoot = try AbsolutePath(validating: projectRoot.filePath) let hostSDK = try SwiftSDK.hostSwiftSDK(AbsolutePath(validating: destinationToolchainBinDir.filePath)) let hostSwiftPMToolchain = try UserToolchain(swiftSDK: hostSDK) @@ -237,10 +237,10 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem { fileSystem: localFileSystem ) - if options.backgroundIndexingOrDefault { - location.scratchDirectory = absProjectRoot.appending(components: ".build", "index-build") - } else if let scratchDirectory = options.swiftPMOrDefault.scratchPath { + if let scratchDirectory = options.swiftPMOrDefault.scratchPath { location.scratchDirectory = try AbsolutePath(validating: scratchDirectory, relativeTo: absProjectRoot) + } else if options.backgroundIndexingOrDefault { + location.scratchDirectory = absProjectRoot.appending(components: ".build", "index-build") } var configuration = WorkspaceConfiguration.default diff --git a/Sources/InProcessClient/InProcessSourceKitLSPClient.swift b/Sources/InProcessClient/InProcessSourceKitLSPClient.swift index a4628c3be..6ee01360f 100644 --- a/Sources/InProcessClient/InProcessSourceKitLSPClient.swift +++ b/Sources/InProcessClient/InProcessSourceKitLSPClient.swift @@ -15,7 +15,7 @@ public import Foundation public import LanguageServerProtocol import LanguageServerProtocolExtensions import SKLogging -package import SKOptions +public import SKOptions package import SourceKitLSP import SwiftExtensions import TSCExtensions @@ -31,13 +31,14 @@ public final class InProcessSourceKitLSPClient: Sendable { public convenience init( toolchainPath: URL?, + options: SourceKitLSPOptions = SourceKitLSPOptions(), capabilities: ClientCapabilities = ClientCapabilities(), workspaceFolders: [WorkspaceFolder], messageHandler: any MessageHandler ) async throws { try await self.init( toolchainRegistry: ToolchainRegistry(installPath: toolchainPath), - options: SourceKitLSPOptions(), + options: options, capabilities: capabilities, workspaceFolders: workspaceFolders, messageHandler: messageHandler From d5926bf69f3de44bdcc3da1abf49591ce8440e12 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Mon, 30 Jun 2025 17:08:05 -0700 Subject: [PATCH 2/2] Run formatting after swift-format changes --- Sources/SemanticIndex/PreparationTaskDescription.swift | 7 ++++--- Sources/SemanticIndex/SemanticIndexManager.swift | 7 ++++--- .../SemanticIndex/UpdateIndexStoreTaskDescription.swift | 7 ++++--- Sources/SourceKitLSP/SourceKitLSPServer.swift | 7 ++++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/SemanticIndex/PreparationTaskDescription.swift b/Sources/SemanticIndex/PreparationTaskDescription.swift index 841c81bf1..b4262d7b7 100644 --- a/Sources/SemanticIndex/PreparationTaskDescription.swift +++ b/Sources/SemanticIndex/PreparationTaskDescription.swift @@ -63,9 +63,10 @@ package struct PreparationTaskDescription: IndexTaskDescription { targetsToPrepare: [BuildTargetIdentifier], buildSystemManager: BuildSystemManager, preparationUpToDateTracker: UpToDateTracker, - logMessageToIndexLog: @escaping @Sendable ( - _ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind - ) -> Void, + logMessageToIndexLog: + @escaping @Sendable ( + _ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind + ) -> Void, hooks: IndexHooks ) { self.targetsToPrepare = targetsToPrepare diff --git a/Sources/SemanticIndex/SemanticIndexManager.swift b/Sources/SemanticIndex/SemanticIndexManager.swift index 9699a480f..67257cd2f 100644 --- a/Sources/SemanticIndex/SemanticIndexManager.swift +++ b/Sources/SemanticIndex/SemanticIndexManager.swift @@ -261,9 +261,10 @@ package final actor SemanticIndexManager { updateIndexStoreTimeout: Duration, hooks: IndexHooks, indexTaskScheduler: TaskScheduler, - logMessageToIndexLog: @escaping @Sendable ( - _ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind - ) -> Void, + logMessageToIndexLog: + @escaping @Sendable ( + _ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind + ) -> Void, indexTasksWereScheduled: @escaping @Sendable (Int) -> Void, indexProgressStatusDidChange: @escaping @Sendable () -> Void ) { diff --git a/Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift b/Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift index 319341b71..7bd2362c9 100644 --- a/Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift +++ b/Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift @@ -146,9 +146,10 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription { index: UncheckedIndex, indexStoreUpToDateTracker: UpToDateTracker, indexFilesWithUpToDateUnit: Bool, - logMessageToIndexLog: @escaping @Sendable ( - _ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind - ) -> Void, + logMessageToIndexLog: + @escaping @Sendable ( + _ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind + ) -> Void, timeout: Duration, hooks: IndexHooks ) { diff --git a/Sources/SourceKitLSP/SourceKitLSPServer.swift b/Sources/SourceKitLSP/SourceKitLSPServer.swift index e21bffc95..1dd4aee1b 100644 --- a/Sources/SourceKitLSP/SourceKitLSPServer.swift +++ b/Sources/SourceKitLSP/SourceKitLSPServer.swift @@ -390,9 +390,10 @@ package actor SourceKitLSPServer { private func handleRequest( for request: RequestAndReply, - requestHandler: @Sendable @escaping ( - RequestType, Workspace, LanguageService - ) async throws -> + requestHandler: + @Sendable @escaping ( + RequestType, Workspace, LanguageService + ) async throws -> RequestType.Response ) async { await request.reply {