Skip to content

Commit 2f0a8af

Browse files
authored
Merge pull request #2193 from bnbarham/allow-scratch-override
Allow overriding SwiftPM's build directory with background indexing
2 parents 8968885 + d5926bf commit 2f0a8af

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
203203
throw Error.cannotDetermineHostToolchain
204204
}
205205

206-
var absProjectRoot = try AbsolutePath(validating: projectRoot.filePath)
206+
let absProjectRoot = try AbsolutePath(validating: projectRoot.filePath)
207207
let hostSDK = try SwiftSDK.hostSwiftSDK(AbsolutePath(validating: destinationToolchainBinDir.filePath))
208208
let hostSwiftPMToolchain = try UserToolchain(swiftSDK: hostSDK)
209209

@@ -237,10 +237,10 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
237237
fileSystem: localFileSystem
238238
)
239239

240-
if options.backgroundIndexingOrDefault {
241-
location.scratchDirectory = absProjectRoot.appending(components: ".build", "index-build")
242-
} else if let scratchDirectory = options.swiftPMOrDefault.scratchPath {
240+
if let scratchDirectory = options.swiftPMOrDefault.scratchPath {
243241
location.scratchDirectory = try AbsolutePath(validating: scratchDirectory, relativeTo: absProjectRoot)
242+
} else if options.backgroundIndexingOrDefault {
243+
location.scratchDirectory = absProjectRoot.appending(components: ".build", "index-build")
244244
}
245245

246246
var configuration = WorkspaceConfiguration.default

Sources/InProcessClient/InProcessSourceKitLSPClient.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public import Foundation
1515
public import LanguageServerProtocol
1616
import LanguageServerProtocolExtensions
1717
import SKLogging
18-
package import SKOptions
18+
public import SKOptions
1919
package import SourceKitLSP
2020
import SwiftExtensions
2121
import TSCExtensions
@@ -31,13 +31,14 @@ public final class InProcessSourceKitLSPClient: Sendable {
3131

3232
public convenience init(
3333
toolchainPath: URL?,
34+
options: SourceKitLSPOptions = SourceKitLSPOptions(),
3435
capabilities: ClientCapabilities = ClientCapabilities(),
3536
workspaceFolders: [WorkspaceFolder],
3637
messageHandler: any MessageHandler
3738
) async throws {
3839
try await self.init(
3940
toolchainRegistry: ToolchainRegistry(installPath: toolchainPath),
40-
options: SourceKitLSPOptions(),
41+
options: options,
4142
capabilities: capabilities,
4243
workspaceFolders: workspaceFolders,
4344
messageHandler: messageHandler

Sources/SemanticIndex/PreparationTaskDescription.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ package struct PreparationTaskDescription: IndexTaskDescription {
6363
targetsToPrepare: [BuildTargetIdentifier],
6464
buildSystemManager: BuildSystemManager,
6565
preparationUpToDateTracker: UpToDateTracker<BuildTargetIdentifier, DummySecondaryKey>,
66-
logMessageToIndexLog: @escaping @Sendable (
67-
_ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind
68-
) -> Void,
66+
logMessageToIndexLog:
67+
@escaping @Sendable (
68+
_ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind
69+
) -> Void,
6970
hooks: IndexHooks
7071
) {
7172
self.targetsToPrepare = targetsToPrepare

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@ package final actor SemanticIndexManager {
261261
updateIndexStoreTimeout: Duration,
262262
hooks: IndexHooks,
263263
indexTaskScheduler: TaskScheduler<AnyIndexTaskDescription>,
264-
logMessageToIndexLog: @escaping @Sendable (
265-
_ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind
266-
) -> Void,
264+
logMessageToIndexLog:
265+
@escaping @Sendable (
266+
_ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind
267+
) -> Void,
267268
indexTasksWereScheduled: @escaping @Sendable (Int) -> Void,
268269
indexProgressStatusDidChange: @escaping @Sendable () -> Void
269270
) {

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
146146
index: UncheckedIndex,
147147
indexStoreUpToDateTracker: UpToDateTracker<DocumentURI, BuildTargetIdentifier>,
148148
indexFilesWithUpToDateUnit: Bool,
149-
logMessageToIndexLog: @escaping @Sendable (
150-
_ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind
151-
) -> Void,
149+
logMessageToIndexLog:
150+
@escaping @Sendable (
151+
_ message: String, _ type: WindowMessageType, _ structure: StructuredLogKind
152+
) -> Void,
152153
timeout: Duration,
153154
hooks: IndexHooks
154155
) {

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,10 @@ package actor SourceKitLSPServer {
390390

391391
private func handleRequest<RequestType: TextDocumentRequest>(
392392
for request: RequestAndReply<RequestType>,
393-
requestHandler: @Sendable @escaping (
394-
RequestType, Workspace, LanguageService
395-
) async throws ->
393+
requestHandler:
394+
@Sendable @escaping (
395+
RequestType, Workspace, LanguageService
396+
) async throws ->
396397
RequestType.Response
397398
) async {
398399
await request.reply {

0 commit comments

Comments
 (0)