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