@@ -317,45 +317,44 @@ extension SourceKitServer {
317
317
318
318
// Now, call `editsToRename(locations:in:oldName:newName:)` on the language service to convert these ranges into
319
319
// edits.
320
- await withTaskGroup ( of: ( DocumentURI, [ TextEdit] ) ? . self) { taskGroup in
321
- for (url, renameLocations) in locationsByFile {
320
+ let urisAndEdits =
321
+ await locationsByFile
322
+ . filter { changes [ DocumentURI ( $0. key) ] == nil }
323
+ . concurrentMap { ( url: URL , renameLocations: [ RenameLocation ] ) -> ( DocumentURI , [ TextEdit ] ) ? in
322
324
let uri = DocumentURI ( url)
323
- if changes [ uri] != nil {
324
- // We already have edits for this document provided by the language service, so we don't need to compute
325
- // rename ranges for it.
326
- continue
325
+ // Create a document snapshot to operate on. If the document is open, load it from the document manager,
326
+ // otherwise conjure one from the file on disk. We need the file in memory to perform UTF-8 to UTF-16 column
327
+ // conversions.
328
+ // We should technically infer the language for the from-disk snapshot. But `editsToRename` doesn't care
329
+ // about it, so defaulting to Swift is good enough for now
330
+ // If we fail to get edits for one file, log an error and continue but don't fail rename completely.
331
+ guard
332
+ let snapshot = ( try ? self . documentManager. latestSnapshot ( uri) )
333
+ ?? ( try ? DocumentSnapshot ( url, language: . swift) )
334
+ else {
335
+ logger. error ( " Failed to get document snapshot for \( uri. forLogging) " )
336
+ return nil
327
337
}
328
- taskGroup. addTask {
329
- // Create a document snapshot to operate on. If the document is open, load it from the document manager,
330
- // otherwise conjure one from the file on disk. We need the file in memory to perform UTF-8 to UTF-16 column
331
- // conversions.
332
- // We should technically infer the language for the from-disk snapshot. But `editsToRename` doesn't care
333
- // about it, so defaulting to Swift is good enough for now
334
- // If we fail to get edits for one file, log an error and continue but don't fail rename completely.
335
- guard
336
- let snapshot = ( try ? self . documentManager. latestSnapshot ( uri) )
337
- ?? ( try ? DocumentSnapshot ( url, language: . swift) )
338
- else {
339
- logger. error ( " Failed to get document snapshot for \( uri. forLogging) " )
340
- return nil
341
- }
342
- do {
343
- let edits = try await languageService. editsToRename (
344
- locations: renameLocations,
345
- in: snapshot,
346
- oldName: oldName,
347
- newName: request. newName
348
- )
349
- return ( uri, edits)
350
- } catch {
351
- logger. error ( " Failed to get edits for \( uri. forLogging) : \( error. forLogging) " )
352
- return nil
353
- }
338
+ do {
339
+ let edits = try await languageService. editsToRename (
340
+ locations: renameLocations,
341
+ in: snapshot,
342
+ oldName: oldName,
343
+ newName: request. newName
344
+ )
345
+ return ( uri, edits)
346
+ } catch {
347
+ logger. error ( " Failed to get edits for \( uri. forLogging) : \( error. forLogging) " )
348
+ return nil
354
349
}
355
- }
356
- for await case let ( uri, textEdits) ? in taskGroup where !textEdits. isEmpty {
357
- precondition ( changes [ uri] == nil , " We should not create tasks for URIs that already have edits " )
358
- changes [ uri] = textEdits
350
+ } . compactMap { $0 }
351
+ for (uri, editsForUri) in urisAndEdits {
352
+ precondition (
353
+ changes [ uri] == nil ,
354
+ " We should have only computed edits for URIs that didn't have edits from the initial rename request "
355
+ )
356
+ if !editsForUri. isEmpty {
357
+ changes [ uri] = editsForUri
359
358
}
360
359
}
361
360
}
0 commit comments