Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show full context menu when test default action is to show context menu #176328

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions src/vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
});
}));
});
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/contrib/testing/browser/testingDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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>(EditorLineNumberContextMenu.ID)?.show(e);
}

private getGutterLabel() {
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand Down