From e4cc1aa001a3fdaed2ad646ffd2e75925bb87196 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Tue, 7 Mar 2023 01:10:36 +0000 Subject: [PATCH] Show full context menu when test default action is to show context menu --- .../browser/editorLineNumberMenu.ts | 54 +++++++++---------- .../testing/browser/testingDecorations.ts | 12 ++--- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu.ts b/src/vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu.ts index 92b281c4348a5..2edd8b713a02e 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu.ts @@ -5,7 +5,7 @@ import { IAction, Separator } from 'vs/base/common/actions'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; -import { ICodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser'; +import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution, EditorContributionInstantiation } from 'vs/editor/browser/editorExtensions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { IMenuService, MenuId } from 'vs/platform/actions/common/actions'; @@ -56,43 +56,41 @@ export class EditorLineNumberContextMenu extends Disposable implements IEditorCo ) { super(); - this.registerListeners(); + this._register(this.editor.onContextMenu((e: IEditorMouseEvent) => this.show(e))); } - private registerListeners(): void { - this._register(this.editor.onContextMenu((e) => { - const menu = this.menuService.createMenu(MenuId.EditorLineNumberContext, this.contextKeyService); + public show(e: IEditorMouseEvent) { + const menu = this.menuService.createMenu(MenuId.EditorLineNumberContext, this.contextKeyService); - const model = this.editor.getModel(); - if (!e.target.position || !model || e.target.type !== MouseTargetType.GUTTER_LINE_NUMBERS && e.target.type !== MouseTargetType.GUTTER_GLYPH_MARGIN) { - return; - } + const model = this.editor.getModel(); + if (!e.target.position || !model || e.target.type !== MouseTargetType.GUTTER_LINE_NUMBERS && e.target.type !== MouseTargetType.GUTTER_GLYPH_MARGIN) { + return; + } - const anchor = { x: e.event.posx, y: e.event.posy }; - const lineNumber = e.target.position.lineNumber; + const anchor = { x: e.event.posx, y: e.event.posy }; + const lineNumber = e.target.position.lineNumber; - const actions: IAction[][] = []; + const actions: IAction[][] = []; - this.instantiationService.invokeFunction(accessor => { - for (const generator of GutterActionsRegistry.getGutterActionsGenerators()) { - const collectedActions: IAction[] = []; - generator({ lineNumber, editor: this.editor, accessor }, { push: (action: IAction) => collectedActions.push(action) }); - actions.push(collectedActions); - } + this.instantiationService.invokeFunction(accessor => { + for (const generator of GutterActionsRegistry.getGutterActionsGenerators()) { + const collectedActions: IAction[] = []; + generator({ lineNumber, editor: this.editor, accessor }, { push: (action: IAction) => collectedActions.push(action) }); + actions.push(collectedActions); + } - const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri }, shouldForwardArgs: true }); - actions.push(...menuActions.map(a => a[1])); + const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri }, shouldForwardArgs: true }); + actions.push(...menuActions.map(a => a[1])); - this.contextMenuService.showContextMenu({ - getAnchor: () => anchor, - getActions: () => Separator.join(...actions), - menuActionOptions: { shouldForwardArgs: true }, - getActionsContext: () => ({ lineNumber, uri: model.uri }), - onHide: () => menu.dispose(), - }); + this.contextMenuService.showContextMenu({ + getAnchor: () => anchor, + getActions: () => Separator.join(...actions), + menuActionOptions: { shouldForwardArgs: true }, + getActionsContext: () => ({ lineNumber, uri: model.uri }), + onHide: () => menu.dispose(), }); - })); + }); } } diff --git a/src/vs/workbench/contrib/testing/browser/testingDecorations.ts b/src/vs/workbench/contrib/testing/browser/testingDecorations.ts index bbbd84f34acfb..83e33f127fc58 100644 --- a/src/vs/workbench/contrib/testing/browser/testingDecorations.ts +++ b/src/vs/workbench/contrib/testing/browser/testingDecorations.ts @@ -50,7 +50,7 @@ import { LiveTestResult } from 'vs/workbench/contrib/testing/common/testResult'; import { ITestResultService } from 'vs/workbench/contrib/testing/common/testResultService'; import { getContextForTestItem, ITestService, testsInFile } from 'vs/workbench/contrib/testing/common/testService'; import { IncrementalTestCollectionItem, InternalTestItem, IRichLocation, ITestMessage, ITestRunProfile, TestDiffOpType, TestMessageType, TestResultItem, TestResultState, TestRunProfileBitset } from 'vs/workbench/contrib/testing/common/testTypes'; -import { GutterActionsRegistry } from 'vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu'; +import { EditorLineNumberContextMenu, GutterActionsRegistry } from 'vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu'; const MAX_INLINE_MESSAGE_LENGTH = 128; @@ -711,6 +711,7 @@ abstract class RunTestDecoration { }[], private visible: boolean, protected readonly model: ITextModel, + @ICodeEditorService private readonly codeEditorService: ICodeEditorService, @ITestService protected readonly testService: ITestService, @IContextMenuService protected readonly contextMenuService: IContextMenuService, @ICommandService protected readonly commandService: ICommandService, @@ -794,10 +795,8 @@ abstract class RunTestDecoration { } private showContextMenu(e: IEditorMouseEvent) { - this.contextMenuService.showContextMenu({ - menuId: MenuId.EditorLineNumberContext, - getAnchor: () => ({ x: e.event.posx, y: e.event.posy }), - }); + const editor = this.codeEditorService.listCodeEditors().find(e => e.getModel() === this.model); + editor?.getContribution(EditorLineNumberContextMenu.ID)?.show(e); } private getGutterLabel() { @@ -933,6 +932,7 @@ class RunSingleTestDecoration extends RunTestDecoration implements ITestDecorati resultItem: TestResultItem | undefined, model: ITextModel, visible: boolean, + @ICodeEditorService codeEditorService: ICodeEditorService, @ITestService testService: ITestService, @ICommandService commandService: ICommandService, @IContextMenuService contextMenuService: IContextMenuService, @@ -941,7 +941,7 @@ class RunSingleTestDecoration extends RunTestDecoration implements ITestDecorati @IContextKeyService contextKeyService: IContextKeyService, @IMenuService menuService: IMenuService, ) { - super([{ test, resultItem }], visible, model, testService, contextMenuService, commandService, configurationService, testProfiles, contextKeyService, menuService); + super([{ test, resultItem }], visible, model, codeEditorService, testService, contextMenuService, commandService, configurationService, testProfiles, contextKeyService, menuService); } override getContextMenuActions() {