Use toAction instead of new Action to prevent some leaks

This commit is contained in:
Matt Bierner
2025-10-20 14:47:18 -07:00
parent 986516b4bf
commit 0d1cb5e746
2 changed files with 22 additions and 23 deletions

View File

@@ -52,6 +52,11 @@ export interface IActionChangeEvent {
readonly checked?: boolean;
}
/**
* A concrete implementation of {@link IAction}.
*
* Note that in most cases you should use the lighter-weight {@linkcode toAction} function instead.
*/
export class Action extends Disposable implements IAction {
protected _onDidChange = this._register(new Emitter<IActionChangeEvent>());

View File

@@ -14,7 +14,7 @@ import { renderLabelWithIcons } from '../../../../base/browser/ui/iconLabel/icon
import { IIdentityProvider, IKeyboardNavigationLabelProvider, IListVirtualDelegate } from '../../../../base/browser/ui/list/list.js';
import { DefaultKeyboardNavigationDelegate, IListAccessibilityProvider } from '../../../../base/browser/ui/list/listWidget.js';
import { ITreeContextMenuEvent, ITreeFilter, ITreeNode, ITreeRenderer, ITreeSorter, TreeFilterResult, TreeVisibility } from '../../../../base/browser/ui/tree/tree.js';
import { Action, ActionRunner, IAction, Separator } from '../../../../base/common/actions.js';
import { Action, ActionRunner, IAction, Separator, toAction } from '../../../../base/common/actions.js';
import { mapFindFirst } from '../../../../base/common/arraysFind.js';
import { RunOnceScheduler, disposableTimeout } from '../../../../base/common/async.js';
import { groupBy } from '../../../../base/common/collections.js';
@@ -345,17 +345,15 @@ export class TestingExplorerView extends ViewPane {
if (!hasAdded) {
hasAdded = true;
participatingGroups++;
profileActions.push(new Action(`${controller.id}.$root`, controller.label.get(), undefined, false));
profileActions.push(toAction({ id: `${controller.id}.$root`, label: controller.label.get(), enabled: false, checked: false, run: () => { } }));
}
hasConfigurable = hasConfigurable || profile.hasConfigurationHandler;
participatingProfiles++;
profileActions.push(new Action(
`${controller.id}.${profile.profileId}`,
defaults.includes(profile) ? localize('defaultTestProfile', '{0} (Default)', profile.label) : profile.label,
undefined,
undefined,
() => {
profileActions.push(toAction({
id: `${controller.id}.${profile.profileId}`,
label: defaults.includes(profile) ? localize('defaultTestProfile', '{0} (Default)', profile.label) : profile.label,
run: () => {
const { include, exclude } = this.getTreeIncludeExclude(profile);
this.testService.runResolvedTests({
exclude: exclude.map(e => e.item.extId),
@@ -367,7 +365,7 @@ export class TestingExplorerView extends ViewPane {
}]
});
},
));
}));
}
}
@@ -390,23 +388,19 @@ export class TestingExplorerView extends ViewPane {
const postActions: IAction[] = [];
if (participatingProfiles > 1) {
postActions.push(new Action(
'selectDefaultTestConfigurations',
localize('selectDefaultConfigs', 'Select Default Profile'),
undefined,
undefined,
() => this.commandService.executeCommand<ITestRunProfile>(TestCommandId.SelectDefaultTestProfiles, group),
));
postActions.push(toAction({
id: 'selectDefaultTestConfigurations',
label: localize('selectDefaultConfigs', 'Select Default Profile'),
run: () => this.commandService.executeCommand<ITestRunProfile>(TestCommandId.SelectDefaultTestProfiles, group),
}));
}
if (hasConfigurable) {
postActions.push(new Action(
'configureTestProfiles',
localize('configureTestProfiles', 'Configure Test Profiles'),
undefined,
undefined,
() => this.commandService.executeCommand<ITestRunProfile>(TestCommandId.ConfigureTestProfilesAction, group),
));
postActions.push(toAction({
id: 'configureTestProfiles',
label: localize('configureTestProfiles', 'Configure Test Profiles'),
run: () => this.commandService.executeCommand<ITestRunProfile>(TestCommandId.ConfigureTestProfilesAction, group),
}));
}
// show menu actions if there are any otherwise don't