@@ -22,7 +22,7 @@ import struct TSCBasic.RelativePath
22
22
23
23
// FIXME: (BSP Migration) This should be a MessageHandler once we have migrated all build system queries to BSP and can use
24
24
// LocalConnection for the communication.
25
- protocol BuiltInBuildSystemAdapterDelegate : Sendable {
25
+ protocol BuiltInBuildSystemAdapterDelegate : Sendable , AnyObject {
26
26
func handle( _ notification: some NotificationType ) async
27
27
func handle< R: RequestType > ( _ request: R ) async throws -> R . Response
28
28
}
@@ -74,7 +74,7 @@ package actor BuiltInBuildSystemAdapter: BuiltInBuildSystemMessageHandler {
74
74
// FIXME: (BSP Migration) This should be private, all messages should go through BSP. Only accessible from the outside for transition
75
75
// purposes.
76
76
private( set) package var underlyingBuildSystem : BuiltInBuildSystem !
77
- private let messageHandler : any BuiltInBuildSystemAdapterDelegate
77
+ private weak var messageHandler : ( any BuiltInBuildSystemAdapterDelegate ) ?
78
78
79
79
init ? (
80
80
buildSystemKind: ( WorkspaceType , projectRoot: AbsolutePath ) ? ,
@@ -163,6 +163,10 @@ package actor BuiltInBuildSystemAdapter: BuiltInBuildSystemMessageHandler {
163
163
\( notification. forLogging)
164
164
"""
165
165
)
166
+ guard let messageHandler else {
167
+ logger. error ( " Ignoring notificaiton \( notification. forLogging) because message handler has been deallocated " )
168
+ return
169
+ }
166
170
await messageHandler. handle ( notification)
167
171
}
168
172
@@ -173,6 +177,9 @@ package actor BuiltInBuildSystemAdapter: BuiltInBuildSystemMessageHandler {
173
177
\( request. forLogging)
174
178
"""
175
179
)
180
+ guard let messageHandler else {
181
+ throw ResponseError . unknown ( " Connection to SourceKit-LSP closed " )
182
+ }
176
183
return try await messageHandler. handle ( request)
177
184
}
178
185
0 commit comments