From 489672365ef6fc7f929b1fb1f0508e2cfd411fe5 Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 28 Aug 2020 15:07:25 +0200 Subject: [PATCH] Expose the contribution.menus for Variable view fixes #70377 --- .../workbench/api/common/menusExtensionPoint.ts | 7 ++++++- .../contrib/debug/browser/debugToolBar.ts | 2 -- .../contrib/debug/browser/variablesView.ts | 15 ++++++++++++++- .../workbench/contrib/debug/common/debugModel.ts | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/api/common/menusExtensionPoint.ts b/src/vs/workbench/api/common/menusExtensionPoint.ts index 25e3d1e692d..445d2b49ba4 100644 --- a/src/vs/workbench/api/common/menusExtensionPoint.ts +++ b/src/vs/workbench/api/common/menusExtensionPoint.ts @@ -61,7 +61,12 @@ const apiMenus: IAPIMenu[] = [ { key: 'debug/callstack/context', id: MenuId.DebugCallStackContext, - description: localize('menus.debugCallstackContext', "The debug callstack context menu") + description: localize('menus.debugCallstackContext', "The debug callstack view context menu") + }, + { + key: 'debug/variables/context', + id: MenuId.DebugVariablesContext, + description: localize('menus.debugVariablesContext', "The debug variables view context menu") }, { key: 'debug/toolBar', diff --git a/src/vs/workbench/contrib/debug/browser/debugToolBar.ts b/src/vs/workbench/contrib/debug/browser/debugToolBar.ts index 54c7593b579..7f60e726eef 100644 --- a/src/vs/workbench/contrib/debug/browser/debugToolBar.ts +++ b/src/vs/workbench/contrib/debug/browser/debugToolBar.ts @@ -21,7 +21,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { registerThemingParticipant, IThemeService, Themable } from 'vs/platform/theme/common/themeService'; import { registerColor, contrastBorder, widgetShadow } from 'vs/platform/theme/common/colorRegistry'; import { localize } from 'vs/nls'; -import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { RunOnceScheduler } from 'vs/base/common/async'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -58,7 +57,6 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution { @IThemeService themeService: IThemeService, @IInstantiationService private readonly instantiationService: IInstantiationService, @IMenuService menuService: IMenuService, - @IContextMenuService contextMenuService: IContextMenuService, @IContextKeyService contextKeyService: IContextKeyService ) { super(themeService); diff --git a/src/vs/workbench/contrib/debug/browser/variablesView.ts b/src/vs/workbench/contrib/debug/browser/variablesView.ts index 16b982c463a..6059c435dd1 100644 --- a/src/vs/workbench/contrib/debug/browser/variablesView.ts +++ b/src/vs/workbench/contrib/debug/browser/variablesView.ts @@ -34,6 +34,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { withUndefinedAsNull } from 'vs/base/common/types'; +import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions'; +import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; const $ = dom.$; let forgetScopes = true; @@ -47,6 +49,7 @@ export class VariablesView extends ViewPane { private tree!: WorkbenchAsyncDataTree; private savedViewState = new Map(); private autoExpandedScopes = new Set(); + private menu: IMenu; constructor( options: IViewletViewOptions, @@ -61,9 +64,13 @@ export class VariablesView extends ViewPane { @IOpenerService openerService: IOpenerService, @IThemeService themeService: IThemeService, @ITelemetryService telemetryService: ITelemetryService, + @IMenuService menuService: IMenuService ) { super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService); + this.menu = menuService.createMenu(MenuId.DebugVariablesContext, contextKeyService); + this._register(this.menu); + // Use scheduler to prevent unnecessary flashing this.onFocusStackFrameScheduler = new RunOnceScheduler(async () => { const stackFrame = this.debugService.getViewModel().focusedStackFrame; @@ -213,11 +220,17 @@ export class VariablesView extends ViewPane { } } + const context = { + container: (variable.parent as (Variable | Scope)).toDebugProtocolObject(), + variable: variable.toDebugProtocolObject() + }; + const actionsDisposable = createAndFillInContextMenuActions(this.menu, { arg: context, shouldForwardArgs: false }, actions, this.contextMenuService); + this.contextMenuService.showContextMenu({ getAnchor: () => e.anchor, getActions: () => actions, getActionsContext: () => variable, - onHide: () => dispose(actions) + onHide: () => dispose(actionsDisposable) }); } } diff --git a/src/vs/workbench/contrib/debug/common/debugModel.ts b/src/vs/workbench/contrib/debug/common/debugModel.ts index 1d302de30e3..5ba4e274600 100644 --- a/src/vs/workbench/contrib/debug/common/debugModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugModel.ts @@ -247,6 +247,14 @@ export class Variable extends ExpressionContainer implements IExpression { toString(): string { return `${this.name}: ${this.value}`; } + + toDebugProtocolObject(): DebugProtocol.Variable { + return { + name: this.name, + variablesReference: this.reference || 0, + value: this.value + }; + } } export class Scope extends ExpressionContainer implements IScope { @@ -267,6 +275,14 @@ export class Scope extends ExpressionContainer implements IScope { toString(): string { return this.name; } + + toDebugProtocolObject(): DebugProtocol.Scope { + return { + name: this.name, + variablesReference: this.reference || 0, + expensive: this.expensive + }; + } } export class ErrorScope extends Scope {