File tree Expand file tree Collapse file tree 8 files changed +17
-23
lines changed Expand file tree Collapse file tree 8 files changed +17
-23
lines changed Original file line number Diff line number Diff line change @@ -52,8 +52,10 @@ public protocol BuildSystem: AnyObject {
52
52
/// Path remappings for remapping index data for local use.
53
53
var indexPrefixMappings : [ PathPrefixMapping ] { get async }
54
54
55
- /// Delegate to handle any build system events such as file build settings
56
- /// initial reports as well as changes.
55
+ /// Delegate to handle any build system events such as file build settings initial reports as well as changes.
56
+ ///
57
+ /// The build system must not retain the delegate because the delegate can be the `BuildSystemManager`, which could
58
+ /// result in a retain cycle `BuildSystemManager` -> `BuildSystem` -> `BuildSystemManager`.
57
59
var delegate : BuildSystemDelegate ? { get async }
58
60
59
61
/// Set the build system's delegate.
Original file line number Diff line number Diff line change 12
12
import BuildServerProtocol
13
13
import LanguageServerProtocol
14
14
15
- /// Handles build system events, such as file build settings changes.
15
+ /// Handles build system events, such as file build settings changes.
16
16
public protocol BuildSystemDelegate : AnyObject {
17
17
/// Notify the delegate that the build targets have changed.
18
18
///
Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ extension BuildSystemManager: BuildSystemDelegate {
238
238
}
239
239
}
240
240
241
- extension BuildSystemManager : MainFilesDelegate {
241
+ extension BuildSystemManager {
242
242
// FIXME: Consider debouncing/limiting this, seems to trigger often during a build.
243
243
/// Checks if there are any files in `mainFileAssociations` where the main file
244
244
/// that we have stored has changed.
Original file line number Diff line number Diff line change @@ -25,10 +25,3 @@ public protocol MainFilesProvider: AnyObject {
25
25
/// ```
26
26
func mainFilesContainingFile( _: DocumentURI ) async -> Set < DocumentURI >
27
27
}
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
- }
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public actor SourceKitIndexDelegate: IndexDelegate {
23
23
let queue = AsyncQueue < Serial > ( )
24
24
25
25
/// Registered `MainFilesDelegate`s to notify when main files change.
26
- var mainFilesDelegates : [ MainFilesDelegate ] = [ ]
26
+ var mainFilesChangedCallbacks : [ ( ) async -> Void ] = [ ]
27
27
28
28
/// The count of pending unit events. Whenever this transitions to 0, it represents a time where
29
29
/// the index finished processing known events. Of course, that may have already changed by the
@@ -62,20 +62,16 @@ public actor SourceKitIndexDelegate: IndexDelegate {
62
62
}
63
63
64
64
func _indexChanged( ) {
65
- for delegate in mainFilesDelegates {
65
+ for callback in mainFilesChangedCallbacks {
66
66
queue. async {
67
- await delegate . mainFilesChanged ( )
67
+ await callback ( )
68
68
}
69
69
}
70
70
}
71
71
72
72
/// 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 )
75
75
}
76
76
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
- }
81
77
}
Original file line number Diff line number Diff line change @@ -1129,7 +1129,8 @@ extension SourceKitServer {
1129
1129
buildSetup: self . options. buildSetup. merging ( workspaceBuildSetup) ,
1130
1130
compilationDatabaseSearchPaths: self . options. compilationDatabaseSearchPaths,
1131
1131
indexOptions: self . options. indexOptions,
1132
- reloadPackageStatusCallback: { status in
1132
+ reloadPackageStatusCallback: { [ weak self] status in
1133
+ guard let self else { return }
1133
1134
guard capabilityRegistry. clientCapabilities. window? . workDoneProgress ?? false else {
1134
1135
// Client doesn’t support work done progress
1135
1136
return
Original file line number Diff line number Diff line change @@ -88,7 +88,9 @@ public final class Workspace {
88
88
fallbackBuildSystem: FallbackBuildSystem ( buildSetup: buildSetup) ,
89
89
mainFilesProvider: index
90
90
)
91
- await indexDelegate? . registerMainFileChanged ( buildSystemManager)
91
+ await indexDelegate? . addMainFileChangedCallback { [ weak self] in
92
+ await self ? . buildSystemManager. mainFilesChanged ( )
93
+ }
92
94
}
93
95
94
96
/// Creates a workspace for a given root `URL`, inferring the `ExternalWorkspace` if possible.
Original file line number Diff line number Diff line change @@ -429,7 +429,7 @@ class ManualBuildSystem: BuildSystem {
429
429
430
430
var map : [ DocumentURI : FileBuildSettings ] = [ : ]
431
431
432
- var delegate : BuildSystemDelegate ? = nil
432
+ weak var delegate : BuildSystemDelegate ? = nil
433
433
434
434
func setDelegate( _ delegate: SKCore . BuildSystemDelegate ? ) async {
435
435
self . delegate = delegate
You can’t perform that action at this time.
0 commit comments