From d346340a4dba77defb58ab6ef9aeace08c7d41f7 Mon Sep 17 00:00:00 2001 From: xyOz Date: Thu, 8 May 2025 21:38:34 +0100 Subject: [PATCH 1/4] maybe maybe --- src/integrations/editor/DiffViewProvider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 0bf494854a..557454080f 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -352,7 +352,9 @@ export class DiffViewProvider { } // close editor if open? - async reset() { + async reset() { + // Ensure any diff views opened by this provider are closed to release memory + await this.closeAllDiffViews(); this.editType = undefined this.isEditing = false this.originalContent = undefined From a39735ac5f711d63cea9c0d25ab4c52167fce146 Mon Sep 17 00:00:00 2001 From: xyOz Date: Sun, 11 May 2025 18:35:23 +0100 Subject: [PATCH 2/4] All tests now pass successfully. Enhance closeAllDiffViews method to safely handle test environments by checking for the existence of the close function on tabGroups before attempting to close tabs. All tests now pass successfully. --- src/integrations/editor/DiffViewProvider.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 557454080f..c495966902 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -250,6 +250,12 @@ export class DiffViewProvider { } private async closeAllDiffViews() { + // Guard for test environments where `tabGroups.close` might be missing from the mocked API + const closeFn = (vscode.window.tabGroups as unknown as { close?: (tab: vscode.Tab) => Thenable | void }).close + if (typeof closeFn !== "function") { + return + } + const tabs = vscode.window.tabGroups.all .flatMap((tg) => tg.tabs) .filter( @@ -260,7 +266,7 @@ export class DiffViewProvider { for (const tab of tabs) { // trying to close dirty views results in save popup if (!tab.isDirty) { - await vscode.window.tabGroups.close(tab) + await closeFn.call(vscode.window.tabGroups, tab) } } } From 04c515c6585cfb41afb8432c530c8a7ebff6c5c6 Mon Sep 17 00:00:00 2001 From: xyOz Date: Sun, 11 May 2025 21:41:15 +0100 Subject: [PATCH 3/4] Improved Test Fixes by cte Oopsie --- src/core/task/__tests__/Task.test.ts | 2 ++ src/integrations/editor/DiffViewProvider.ts | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/task/__tests__/Task.test.ts b/src/core/task/__tests__/Task.test.ts index f70edfdefa..9856b7ec67 100644 --- a/src/core/task/__tests__/Task.test.ts +++ b/src/core/task/__tests__/Task.test.ts @@ -61,6 +61,7 @@ jest.mock("vscode", () => { const mockTabGroup = { tabs: [mockTab] } return { + TabInputTextDiff: jest.fn(), CodeActionKind: { QuickFix: { value: "quickfix" }, RefactorRewrite: { value: "refactor.rewrite" }, @@ -72,6 +73,7 @@ jest.mock("vscode", () => { visibleTextEditors: [mockTextEditor], tabGroups: { all: [mockTabGroup], + close: jest.fn(), onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })), }, showErrorMessage: jest.fn(), diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index c495966902..2ae905f677 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -250,11 +250,6 @@ export class DiffViewProvider { } private async closeAllDiffViews() { - // Guard for test environments where `tabGroups.close` might be missing from the mocked API - const closeFn = (vscode.window.tabGroups as unknown as { close?: (tab: vscode.Tab) => Thenable | void }).close - if (typeof closeFn !== "function") { - return - } const tabs = vscode.window.tabGroups.all .flatMap((tg) => tg.tabs) @@ -266,7 +261,7 @@ export class DiffViewProvider { for (const tab of tabs) { // trying to close dirty views results in save popup if (!tab.isDirty) { - await closeFn.call(vscode.window.tabGroups, tab) + await vscode.window.tabGroups.close(tab) } } } From b88350088b9f1ee6ae687aacb8ba0c2d0fc7fbee Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 12 May 2025 09:59:34 -0400 Subject: [PATCH 4/4] Apply suggestions from code review --- src/integrations/editor/DiffViewProvider.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 2ae905f677..aad715f0ae 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -250,7 +250,6 @@ export class DiffViewProvider { } private async closeAllDiffViews() { - const tabs = vscode.window.tabGroups.all .flatMap((tg) => tg.tabs) .filter( @@ -353,7 +352,7 @@ export class DiffViewProvider { } // close editor if open? - async reset() { + async reset() { // Ensure any diff views opened by this provider are closed to release memory await this.closeAllDiffViews(); this.editType = undefined