Skip to content

Commit 4896723

Browse files
committed
Expose the contribution.menus for Variable view
fixes microsoft#70377
1 parent 2a9a512 commit 4896723

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/vs/workbench/api/common/menusExtensionPoint.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ const apiMenus: IAPIMenu[] = [
6161
{
6262
key: 'debug/callstack/context',
6363
id: MenuId.DebugCallStackContext,
64-
description: localize('menus.debugCallstackContext', "The debug callstack context menu")
64+
description: localize('menus.debugCallstackContext', "The debug callstack view context menu")
65+
},
66+
{
67+
key: 'debug/variables/context',
68+
id: MenuId.DebugVariablesContext,
69+
description: localize('menus.debugVariablesContext', "The debug variables view context menu")
6570
},
6671
{
6772
key: 'debug/toolBar',

src/vs/workbench/contrib/debug/browser/debugToolBar.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2121
import { registerThemingParticipant, IThemeService, Themable } from 'vs/platform/theme/common/themeService';
2222
import { registerColor, contrastBorder, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
2323
import { localize } from 'vs/nls';
24-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
2524
import { INotificationService } from 'vs/platform/notification/common/notification';
2625
import { RunOnceScheduler } from 'vs/base/common/async';
2726
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -58,7 +57,6 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution {
5857
@IThemeService themeService: IThemeService,
5958
@IInstantiationService private readonly instantiationService: IInstantiationService,
6059
@IMenuService menuService: IMenuService,
61-
@IContextMenuService contextMenuService: IContextMenuService,
6260
@IContextKeyService contextKeyService: IContextKeyService
6361
) {
6462
super(themeService);

src/vs/workbench/contrib/debug/browser/variablesView.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
3434
import { IThemeService } from 'vs/platform/theme/common/themeService';
3535
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
3636
import { withUndefinedAsNull } from 'vs/base/common/types';
37+
import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions';
38+
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
3739

3840
const $ = dom.$;
3941
let forgetScopes = true;
@@ -47,6 +49,7 @@ export class VariablesView extends ViewPane {
4749
private tree!: WorkbenchAsyncDataTree<IStackFrame | null, IExpression | IScope, FuzzyScore>;
4850
private savedViewState = new Map<string, IAsyncDataTreeViewState>();
4951
private autoExpandedScopes = new Set<string>();
52+
private menu: IMenu;
5053

5154
constructor(
5255
options: IViewletViewOptions,
@@ -61,9 +64,13 @@ export class VariablesView extends ViewPane {
6164
@IOpenerService openerService: IOpenerService,
6265
@IThemeService themeService: IThemeService,
6366
@ITelemetryService telemetryService: ITelemetryService,
67+
@IMenuService menuService: IMenuService
6468
) {
6569
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
6670

71+
this.menu = menuService.createMenu(MenuId.DebugVariablesContext, contextKeyService);
72+
this._register(this.menu);
73+
6774
// Use scheduler to prevent unnecessary flashing
6875
this.onFocusStackFrameScheduler = new RunOnceScheduler(async () => {
6976
const stackFrame = this.debugService.getViewModel().focusedStackFrame;
@@ -213,11 +220,17 @@ export class VariablesView extends ViewPane {
213220
}
214221
}
215222

223+
const context = {
224+
container: (variable.parent as (Variable | Scope)).toDebugProtocolObject(),
225+
variable: variable.toDebugProtocolObject()
226+
};
227+
const actionsDisposable = createAndFillInContextMenuActions(this.menu, { arg: context, shouldForwardArgs: false }, actions, this.contextMenuService);
228+
216229
this.contextMenuService.showContextMenu({
217230
getAnchor: () => e.anchor,
218231
getActions: () => actions,
219232
getActionsContext: () => variable,
220-
onHide: () => dispose(actions)
233+
onHide: () => dispose(actionsDisposable)
221234
});
222235
}
223236
}

src/vs/workbench/contrib/debug/common/debugModel.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ export class Variable extends ExpressionContainer implements IExpression {
247247
toString(): string {
248248
return `${this.name}: ${this.value}`;
249249
}
250+
251+
toDebugProtocolObject(): DebugProtocol.Variable {
252+
return {
253+
name: this.name,
254+
variablesReference: this.reference || 0,
255+
value: this.value
256+
};
257+
}
250258
}
251259

252260
export class Scope extends ExpressionContainer implements IScope {
@@ -267,6 +275,14 @@ export class Scope extends ExpressionContainer implements IScope {
267275
toString(): string {
268276
return this.name;
269277
}
278+
279+
toDebugProtocolObject(): DebugProtocol.Scope {
280+
return {
281+
name: this.name,
282+
variablesReference: this.reference || 0,
283+
expensive: this.expensive
284+
};
285+
}
270286
}
271287

272288
export class ErrorScope extends Scope {

0 commit comments

Comments
 (0)