Skip to content

Commit 3e4e91e

Browse files
authored
Merge pull request #216018 from microsoft/rainy-dragonfly
Menu contribution to allow extensions to contribute a configuration submenu for testing
2 parents 3e283de + 70f65a6 commit 3e4e91e

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

src/vs/platform/actions/common/actions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export class MenuId {
138138
static readonly StickyScrollContext = new MenuId('StickyScrollContext');
139139
static readonly TestItem = new MenuId('TestItem');
140140
static readonly TestItemGutter = new MenuId('TestItemGutter');
141+
static readonly TestProfilesContext = new MenuId('TestProfilesContext');
141142
static readonly TestMessageContext = new MenuId('TestMessageContext');
142143
static readonly TestMessageContent = new MenuId('TestMessageContent');
143144
static readonly TestPeekElement = new MenuId('TestPeekElement');

src/vs/workbench/contrib/testing/browser/testingExplorerView.ts

+28-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import 'vs/css!./media/testing';
3131
import { MarkdownRenderer } from 'vs/editor/browser/widget/markdownRenderer/browser/markdownRenderer';
3232
import { localize } from 'vs/nls';
3333
import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem';
34-
import { MenuEntryActionViewItem, createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
34+
import { MenuEntryActionViewItem, createActionViewItem, createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
3535
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
3636
import { ICommandService } from 'vs/platform/commands/common/commands';
3737
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -117,6 +117,7 @@ export class TestingExplorerView extends ViewPane {
117117
@IHoverService hoverService: IHoverService,
118118
@ITestProfileService private readonly testProfileService: ITestProfileService,
119119
@ICommandService private readonly commandService: ICommandService,
120+
@IMenuService private readonly menuService: IMenuService,
120121
) {
121122
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService);
122123

@@ -351,10 +352,29 @@ export class TestingExplorerView extends ViewPane {
351352
}
352353
}
353354

354-
// If there's only one group, don't add a heading for it in the dropdown.
355-
if (participatingGroups === 1) {
356-
profileActions.shift();
355+
const menuActions: IAction[] = [];
356+
const contextKeys: [string, unknown][] = [];
357+
// allow extension author to define context for when to show the test menu actions for run or debug menus
358+
if (group === TestRunProfileBitset.Run) {
359+
contextKeys.push(['testing.profile.context.group', 'run']);
360+
}
361+
if (group === TestRunProfileBitset.Debug) {
362+
contextKeys.push(['testing.profile.context.group', 'debug']);
363+
}
364+
if (group === TestRunProfileBitset.Coverage) {
365+
contextKeys.push(['testing.profile.context.group', 'coverage']);
357366
}
367+
const key = this.contextKeyService.createOverlay(contextKeys);
368+
const menu = this.menuService.createMenu(MenuId.TestProfilesContext, key);
369+
370+
// fill if there are any actions
371+
try {
372+
createAndFillInContextMenuActions(menu, undefined, menuActions);
373+
} finally {
374+
menu.dispose();
375+
}
376+
377+
358378

359379
const postActions: IAction[] = [];
360380
if (profileActions.length > 1) {
@@ -377,7 +397,10 @@ export class TestingExplorerView extends ViewPane {
377397
));
378398
}
379399

380-
return Separator.join(profileActions, postActions);
400+
// show menu actions if there are any otherwise don't
401+
return menuActions.length > 0
402+
? Separator.join(profileActions, menuActions, postActions)
403+
: Separator.join(profileActions, postActions);
381404
}
382405

383406
/**

src/vs/workbench/contrib/testing/common/testingContextKeys.ts

+4
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@ export namespace TestingContextKeys {
7575
type: 'string',
7676
description: localize('testing.testResultState', 'Value available testing/item/result indicating the state of the item.')
7777
});
78+
export const testProfileContextGroup = new RawContextKey<string>('testing.profile.context.group', undefined, {
79+
type: 'string',
80+
description: localize('testing.profile.context.group', 'Type of menu where the configure testing profile submenu exists. Either "run", "debug", or "coverage"')
81+
});
7882
}

src/vs/workbench/services/actions/common/menusExtensionPoint.ts

+5
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ const apiMenus: IAPIMenu[] = [
343343
id: MenuId.TestItemGutter,
344344
description: localize('testing.item.gutter.title', "The menu for a gutter decoration for a test item"),
345345
},
346+
{
347+
key: 'testing/profiles/context',
348+
id: MenuId.TestProfilesContext,
349+
description: localize('testing.profiles.context.title', "The menu for configuring testing profiles."),
350+
},
346351
{
347352
key: 'testing/item/result',
348353
id: MenuId.TestPeekElement,

0 commit comments

Comments
 (0)