@@ -177,10 +177,22 @@ public actor SourceKitLSPServer {
177
177
/// Used to cancel the tasks if the client requests cancellation.
178
178
private var inProgressRequests : [ RequestID : Task < ( ) , Never > ] = [ : ]
179
179
180
+ /// Up to 10 request IDs that have recently finished.
181
+ ///
182
+ /// This is only used so we don't log an error when receiving a `CancelRequestNotification` for a request that has
183
+ /// just returned a response.
184
+ private var recentlyFinishedRequests : [ RequestID ] = [ ]
185
+
180
186
/// - Note: Needed so we can set an in-progress request from a different
181
187
/// isolation context.
182
188
private func setInProgressRequest( for id: RequestID , task: Task < ( ) , Never > ? ) {
183
189
self . inProgressRequests [ id] = task
190
+ if task == nil {
191
+ recentlyFinishedRequests. append ( id)
192
+ while recentlyFinishedRequests. count > 10 {
193
+ recentlyFinishedRequests. removeFirst ( )
194
+ }
195
+ }
184
196
}
185
197
186
198
var onExit : ( ) -> Void
@@ -1194,16 +1206,15 @@ extension SourceKitLSPServer {
1194
1206
// Since the request is very cheap to execute and stops other requests
1195
1207
// from performing more work, we execute it with a high priority.
1196
1208
cancellationMessageHandlingQueue. async ( priority: . high) {
1197
- guard let task = await self . inProgressRequests [ notification. id] else {
1209
+ if let task = await self . inProgressRequests [ notification. id] {
1210
+ task. cancel ( )
1211
+ return
1212
+ }
1213
+ if await !self . recentlyFinishedRequests. contains ( notification. id) {
1198
1214
logger. error (
1199
- """
1200
- Cannot cancel request \( notification. id, privacy: . public) because it hasn't been scheduled for execution \
1201
- yet or because the request already returned a response
1202
- """
1215
+ " Cannot cancel request \( notification. id, privacy: . public) because it hasn't been scheduled for execution yet "
1203
1216
)
1204
- return
1205
1217
}
1206
- task. cancel ( )
1207
1218
}
1208
1219
}
1209
1220
0 commit comments