Skip to content

Commit 86e1878

Browse files
committed
Fix a retain cycle
I don’t remember what the exact retain cycle was after fixing it.
1 parent 76684c7 commit 86e1878

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

Sources/SKCore/BuildSystemManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ extension BuildSystemManager: BuildSystemDelegate {
238238
}
239239
}
240240

241-
extension BuildSystemManager: MainFilesDelegate {
241+
extension BuildSystemManager {
242242
// FIXME: Consider debouncing/limiting this, seems to trigger often during a build.
243243
/// Checks if there are any files in `mainFileAssociations` where the main file
244244
/// that we have stored has changed.

Sources/SKCore/MainFilesProvider.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,3 @@ public protocol MainFilesProvider: AnyObject {
2525
/// ```
2626
func mainFilesContainingFile(_: DocumentURI) async -> Set<DocumentURI>
2727
}
28-
29-
/// Delegate that responds to possible main file changes.
30-
public protocol MainFilesDelegate: AnyObject {
31-
32-
/// The mapping from files to main files (may have) changed.
33-
func mainFilesChanged() async
34-
}

Sources/SourceKitLSP/SourceKitIndexDelegate.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public actor SourceKitIndexDelegate: IndexDelegate {
2323
let queue = AsyncQueue<Serial>()
2424

2525
/// Registered `MainFilesDelegate`s to notify when main files change.
26-
var mainFilesDelegates: [MainFilesDelegate] = []
26+
var mainFilesChangedCallbacks: [() async -> Void] = []
2727

2828
/// The count of pending unit events. Whenever this transitions to 0, it represents a time where
2929
/// the index finished processing known events. Of course, that may have already changed by the
@@ -62,20 +62,16 @@ public actor SourceKitIndexDelegate: IndexDelegate {
6262
}
6363

6464
func _indexChanged() {
65-
for delegate in mainFilesDelegates {
65+
for callback in mainFilesChangedCallbacks {
6666
queue.async {
67-
await delegate.mainFilesChanged()
67+
await callback()
6868
}
6969
}
7070
}
7171

7272
/// Register a delegate to receive notifications when main files change.
73-
public func registerMainFileChanged(_ delegate: MainFilesDelegate) {
74-
mainFilesDelegates.append(delegate)
73+
public func addMainFileChangedCallback(_ callback: @escaping () async -> Void) {
74+
mainFilesChangedCallbacks.append(callback)
7575
}
7676

77-
/// Un-register a delegate to receive notifications when main files change.
78-
public func unregisterMainFileChanged(_ delegate: MainFilesDelegate) {
79-
mainFilesDelegates.removeAll(where: { $0 === delegate })
80-
}
8177
}

Sources/SourceKitLSP/Workspace.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ public final class Workspace {
8888
fallbackBuildSystem: FallbackBuildSystem(buildSetup: buildSetup),
8989
mainFilesProvider: index
9090
)
91-
await indexDelegate?.registerMainFileChanged(buildSystemManager)
91+
await indexDelegate?.addMainFileChangedCallback { [weak self] in
92+
await self?.buildSystemManager.mainFilesChanged()
93+
}
9294
}
9395

9496
/// Creates a workspace for a given root `URL`, inferring the `ExternalWorkspace` if possible.

0 commit comments

Comments
 (0)