Skip to content

Commit

Permalink
Merge pull request microsoft#216018 from microsoft/rainy-dragonfly
Browse files Browse the repository at this point in the history
Menu contribution to allow extensions to contribute a configuration submenu for testing
  • Loading branch information
eleanorjboyd authored and aaronchucarroll committed Jul 10, 2024
2 parents 2f7a076 + 926d8e8 commit 32fee10
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class MenuId {
static readonly StickyScrollContext = new MenuId('StickyScrollContext');
static readonly TestItem = new MenuId('TestItem');
static readonly TestItemGutter = new MenuId('TestItemGutter');
static readonly TestProfilesContext = new MenuId('TestProfilesContext');
static readonly TestMessageContext = new MenuId('TestMessageContext');
static readonly TestMessageContent = new MenuId('TestMessageContent');
static readonly TestPeekElement = new MenuId('TestPeekElement');
Expand Down
33 changes: 28 additions & 5 deletions src/vs/workbench/contrib/testing/browser/testingExplorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import 'vs/css!./media/testing';
import { MarkdownRenderer } from 'vs/editor/browser/widget/markdownRenderer/browser/markdownRenderer';
import { localize } from 'vs/nls';
import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem';
import { MenuEntryActionViewItem, createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { MenuEntryActionViewItem, createActionViewItem, createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -117,6 +117,7 @@ export class TestingExplorerView extends ViewPane {
@IHoverService hoverService: IHoverService,
@ITestProfileService private readonly testProfileService: ITestProfileService,
@ICommandService private readonly commandService: ICommandService,
@IMenuService private readonly menuService: IMenuService,
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService);

Expand Down Expand Up @@ -351,10 +352,29 @@ export class TestingExplorerView extends ViewPane {
}
}

// If there's only one group, don't add a heading for it in the dropdown.
if (participatingGroups === 1) {
profileActions.shift();
const menuActions: IAction[] = [];
const contextKeys: [string, unknown][] = [];
// allow extension author to define context for when to show the test menu actions for run or debug menus
if (group === TestRunProfileBitset.Run) {
contextKeys.push(['testing.profile.context.group', 'run']);
}
if (group === TestRunProfileBitset.Debug) {
contextKeys.push(['testing.profile.context.group', 'debug']);
}
if (group === TestRunProfileBitset.Coverage) {
contextKeys.push(['testing.profile.context.group', 'coverage']);
}
const key = this.contextKeyService.createOverlay(contextKeys);
const menu = this.menuService.createMenu(MenuId.TestProfilesContext, key);

// fill if there are any actions
try {
createAndFillInContextMenuActions(menu, undefined, menuActions);
} finally {
menu.dispose();
}



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

return Separator.join(profileActions, postActions);
// show menu actions if there are any otherwise don't
return menuActions.length > 0
? Separator.join(profileActions, menuActions, postActions)
: Separator.join(profileActions, postActions);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/contrib/testing/common/testingContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ export namespace TestingContextKeys {
type: 'string',
description: localize('testing.testResultState', 'Value available testing/item/result indicating the state of the item.')
});
export const testProfileContextGroup = new RawContextKey<string>('testing.profile.context.group', undefined, {
type: 'string',
description: localize('testing.profile.context.group', 'Type of menu where the configure testing profile submenu exists. Either "run", "debug", or "coverage"')
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.TestItemGutter,
description: localize('testing.item.gutter.title', "The menu for a gutter decoration for a test item"),
},
{
key: 'testing/profiles/context',
id: MenuId.TestProfilesContext,
description: localize('testing.profiles.context.title', "The menu for configuring testing profiles."),
},
{
key: 'testing/item/result',
id: MenuId.TestPeekElement,
Expand Down

0 comments on commit 32fee10

Please sign in to comment.