diff --git a/src/vs/editor/contrib/format/browser/format.ts b/src/vs/editor/contrib/format/browser/format.ts index 4d64c886d09cb..42d8cf3d87fe4 100644 --- a/src/vs/editor/contrib/format/browser/format.ts +++ b/src/vs/editor/contrib/format/browser/format.ts @@ -228,32 +228,33 @@ export async function formatDocumentRangesWithProvider( logService.trace(`[format][provideDocumentRangeFormattingEdits] (response)`, provider.extensionId?.value, result); rawEditsList.push(result); } else { + for (const range of ranges) { if (cts.token.isCancellationRequested) { return true; } rawEditsList.push(await computeEdits(range)); } - } - for (let i = 0; i < ranges.length; ++i) { - for (let j = i + 1; j < ranges.length; ++j) { - if (cts.token.isCancellationRequested) { - return true; - } - if (hasIntersectingEdit(rawEditsList[i], rawEditsList[j])) { - // Merge ranges i and j into a single range, recompute the associated edits - const mergedRange = Range.plusRange(ranges[i], ranges[j]); - const edits = await computeEdits(mergedRange); - ranges.splice(j, 1); - ranges.splice(i, 1); - ranges.push(mergedRange); - rawEditsList.splice(j, 1); - rawEditsList.splice(i, 1); - rawEditsList.push(edits); - // Restart scanning - i = 0; - j = 0; + for (let i = 0; i < ranges.length; ++i) { + for (let j = i + 1; j < ranges.length; ++j) { + if (cts.token.isCancellationRequested) { + return true; + } + if (hasIntersectingEdit(rawEditsList[i], rawEditsList[j])) { + // Merge ranges i and j into a single range, recompute the associated edits + const mergedRange = Range.plusRange(ranges[i], ranges[j]); + const edits = await computeEdits(mergedRange); + ranges.splice(j, 1); + ranges.splice(i, 1); + ranges.push(mergedRange); + rawEditsList.splice(j, 1); + rawEditsList.splice(i, 1); + rawEditsList.push(edits); + // Restart scanning + i = 0; + j = 0; + } } } }