Skip to content

Commit bf0407c

Browse files
committed
Don’t pass the finished taskDescription to indexTaskDidFinish callback
This follows the general paradigm that callbacks shouldn’t carry much state and instead only notify an observer that state has changed, which the observer can then poll.
1 parent 097e3e6 commit bf0407c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public final actor SemanticIndexManager {
4949
/// Callback that is called when an index task has finished.
5050
///
5151
/// Currently only used for testing.
52-
private let indexTaskDidFinish: (@Sendable (AnyIndexTaskDescription) -> Void)?
52+
private let indexTaskDidFinish: (@Sendable () -> Void)?
5353

5454
// MARK: - Public API
5555

5656
public init(
5757
index: UncheckedIndex,
5858
buildSystemManager: BuildSystemManager,
5959
indexTaskScheduler: TaskScheduler<AnyIndexTaskDescription>,
60-
indexTaskDidFinish: (@Sendable (AnyIndexTaskDescription) -> Void)?
60+
indexTaskDidFinish: (@Sendable () -> Void)?
6161
) {
6262
self.index = index.checked(for: .modifiedFiles)
6363
self.buildSystemManager = buildSystemManager
@@ -138,7 +138,7 @@ public final actor SemanticIndexManager {
138138
)
139139
)
140140
await self.indexTaskScheduler.schedule(priority: priority, taskDescription).value
141-
self.indexTaskDidFinish?(taskDescription)
141+
self.indexTaskDidFinish?()
142142
}
143143

144144
/// Update the index store for the given files, assuming that their targets have already been prepared.
@@ -154,7 +154,7 @@ public final actor SemanticIndexManager {
154154
for file in files {
155155
self.indexStatus[file] = .upToDate
156156
}
157-
self.indexTaskDidFinish?(taskDescription)
157+
self.indexTaskDidFinish?()
158158
}
159159

160160
/// Index the given set of files at the given priority.

Sources/SourceKitLSP/Workspace.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public struct IndexOptions {
298298
/// A callback that is called when an index task finishes.
299299
///
300300
/// Intended for testing purposes.
301-
public var indexTaskDidFinish: (@Sendable (AnyIndexTaskDescription) -> Void)?
301+
public var indexTaskDidFinish: (@Sendable () -> Void)?
302302

303303
public init(
304304
indexStorePath: AbsolutePath? = nil,
@@ -307,7 +307,7 @@ public struct IndexOptions {
307307
listenToUnitEvents: Bool = true,
308308
enableBackgroundIndexing: Bool = false,
309309
maxCoresPercentageToUseForBackgroundIndexing: Double = 1,
310-
indexTaskDidFinish: (@Sendable (AnyIndexTaskDescription) -> Void)? = nil
310+
indexTaskDidFinish: (@Sendable () -> Void)? = nil
311311
) {
312312
self.indexStorePath = indexStorePath
313313
self.indexDatabasePath = indexDatabasePath

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ final class BackgroundIndexingTests: XCTestCase {
165165

166166
func testBackgroundIndexingHappensWithLowPriority() async throws {
167167
var serverOptions = backgroundIndexingOptions
168-
serverOptions.indexOptions.indexTaskDidFinish = { taskDescription in
168+
serverOptions.indexOptions.indexTaskDidFinish = {
169169
XCTAssert(
170170
Task.currentPriority == .low,
171-
"\(taskDescription.description) ran with priority \(Task.currentPriority)"
171+
"An index task ran with priority \(Task.currentPriority)"
172172
)
173173
}
174174
let project = try await SwiftPMTestProject(

0 commit comments

Comments
 (0)