diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index b6a5b9ac3b..da5bb4b2a5 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -298,21 +298,24 @@ export class DiffViewProvider { await this.reset() } - private async closeAllDiffViews() { - const tabs = vscode.window.tabGroups.all - .flatMap((tg) => tg.tabs) - .filter( - (tab) => - tab.input instanceof vscode.TabInputTextDiff && - tab.input?.original?.scheme === DIFF_VIEW_URI_SCHEME, - ) - - for (const tab of tabs) { - // Trying to close dirty views results in save popup. - if (!tab.isDirty) { - await vscode.window.tabGroups.close(tab) + private async closeAllDiffViews(): Promise { + const closeOps = vscode.window.tabGroups.all + .flatMap(group => group.tabs) + .filter( + tab => + tab.input instanceof vscode.TabInputTextDiff && + tab.input.original.scheme === DIFF_VIEW_URI_SCHEME && + !tab.isDirty + ) + .map(tab => + vscode.window.tabGroups.close(tab).then( + () => undefined, + err => { + console.error(`Failed to close diff tab ${tab.label}`, err); } - } + )); + + await Promise.all(closeOps); } private async openDiffEditor(): Promise { @@ -419,15 +422,8 @@ export class DiffViewProvider { return result } - async reset() { - // Ensure any diff views opened by this provider are closed to release - // memory. - try { - await this.closeAllDiffViews() - } catch (error) { - console.error("Error closing diff views", error) - } - + async reset() : Promise { + await this.closeAllDiffViews() this.editType = undefined this.isEditing = false this.originalContent = undefined