Skip to content

Commit 4b54344

Browse files
committed
debug: respect __vscodeVariableMenuContext
microsoft#70377
1 parent 6aafc4b commit 4b54344

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
88
import * as dom from 'vs/base/browser/dom';
99
import { CollapseAction } from 'vs/workbench/browser/viewlet';
1010
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
11-
import { IDebugService, IExpression, IScope, CONTEXT_VARIABLES_FOCUSED, IStackFrame } from 'vs/workbench/contrib/debug/common/debug';
11+
import { IDebugService, IExpression, IScope, CONTEXT_VARIABLES_FOCUSED, IStackFrame, CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT } from 'vs/workbench/contrib/debug/common/debug';
1212
import { Variable, Scope, ErrorScope, StackFrame } from 'vs/workbench/contrib/debug/common/debugModel';
1313
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1414
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
@@ -27,7 +27,7 @@ import { IAsyncDataTreeViewState } from 'vs/base/browser/ui/tree/asyncDataTree';
2727
import { FuzzyScore, createMatches } from 'vs/base/common/filters';
2828
import { HighlightedLabel, IHighlight } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
2929
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
30-
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
30+
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
3131
import { dispose } from 'vs/base/common/lifecycle';
3232
import { IViewDescriptorService } from 'vs/workbench/common/views';
3333
import { IOpenerService } from 'vs/platform/opener/common/opener';
@@ -50,6 +50,7 @@ export class VariablesView extends ViewPane {
5050
private savedViewState = new Map<string, IAsyncDataTreeViewState>();
5151
private autoExpandedScopes = new Set<string>();
5252
private menu: IMenu;
53+
private debugProtocolVariableMenuContext: IContextKey<string>;
5354

5455
constructor(
5556
options: IViewletViewOptions,
@@ -70,6 +71,7 @@ export class VariablesView extends ViewPane {
7071

7172
this.menu = menuService.createMenu(MenuId.DebugVariablesContext, contextKeyService);
7273
this._register(this.menu);
74+
this.debugProtocolVariableMenuContext = CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT.bindTo(contextKeyService);
7375

7476
// Use scheduler to prevent unnecessary flashing
7577
this.onFocusStackFrameScheduler = new RunOnceScheduler(async () => {
@@ -193,29 +195,27 @@ export class VariablesView extends ViewPane {
193195
const actions: IAction[] = [];
194196
const session = this.debugService.getViewModel().focusedSession;
195197
if (session && session.capabilities.supportsSetVariable) {
196-
actions.push(new Action('workbench.setValue', nls.localize('setValue', "Set Value"), undefined, true, () => {
198+
actions.push(new Action('workbench.setValue', nls.localize('setValue', "Set Value"), undefined, true, async () => {
197199
this.debugService.getViewModel().setSelectedExpression(variable);
198-
return Promise.resolve();
199200
}));
200201
}
201202
actions.push(this.instantiationService.createInstance(CopyValueAction, CopyValueAction.ID, CopyValueAction.LABEL, variable, 'variables'));
202203
if (variable.evaluateName) {
203-
actions.push(new Action('debug.copyEvaluatePath', nls.localize('copyAsExpression', "Copy as Expression"), undefined, true, () => {
204-
return this.clipboardService.writeText(variable.evaluateName!);
204+
actions.push(new Action('debug.copyEvaluatePath', nls.localize('copyAsExpression', "Copy as Expression"), undefined, true, async () => {
205+
await this.clipboardService.writeText(variable.evaluateName!);
205206
}));
206207
actions.push(new Separator());
207-
actions.push(new Action('debug.addToWatchExpressions', nls.localize('addToWatchExpressions', "Add to Watch"), undefined, true, () => {
208+
actions.push(new Action('debug.addToWatchExpressions', nls.localize('addToWatchExpressions', "Add to Watch"), undefined, true, async () => {
208209
this.debugService.addWatchExpression(variable.evaluateName);
209-
return Promise.resolve(undefined);
210210
}));
211211
}
212212
if (session && session.capabilities.supportsDataBreakpoints) {
213213
const response = await session.dataBreakpointInfo(variable.name, variable.parent.reference);
214214
const dataid = response?.dataId;
215215
if (response && dataid) {
216216
actions.push(new Separator());
217-
actions.push(new Action('debug.breakWhenValueChanges', nls.localize('breakWhenValueChanges', "Break When Value Changes"), undefined, true, () => {
218-
return this.debugService.addDataBreakpoint(response.description, dataid, !!response.canPersist, response.accessTypes);
217+
actions.push(new Action('debug.breakWhenValueChanges', nls.localize('breakWhenValueChanges', "Break When Value Changes"), undefined, true, async () => {
218+
await this.debugService.addDataBreakpoint(response.description, dataid, !!response.canPersist, response.accessTypes);
219219
}));
220220
}
221221
}
@@ -225,6 +225,7 @@ export class VariablesView extends ViewPane {
225225
variable: variable.toDebugProtocolObject()
226226
};
227227
const actionsDisposable = createAndFillInContextMenuActions(this.menu, { arg: context, shouldForwardArgs: false }, actions, this.contextMenuService);
228+
this.debugProtocolVariableMenuContext.set(variable.variableMenuContext || '');
228229

229230
this.contextMenuService.showContextMenu({
230231
getAnchor: () => e.anchor,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const CONTEXT_JUMP_TO_CURSOR_SUPPORTED = new RawContextKey<boolean>('jump
6060
export const CONTEXT_STEP_INTO_TARGETS_SUPPORTED = new RawContextKey<boolean>('stepIntoTargetsSupported', false);
6161
export const CONTEXT_BREAKPOINTS_EXIST = new RawContextKey<boolean>('breakpointsExist', false);
6262
export const CONTEXT_DEBUGGERS_AVAILABLE = new RawContextKey<boolean>('debuggersAvailable', false);
63+
export const CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT = new RawContextKey<string>('debugProtocolVariableMenuContext', undefined);
6364

6465
export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug';
6566
export const BREAKPOINT_EDITOR_CONTRIBUTION_ID = 'editor.contrib.breakpoint';

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import { mixin } from 'vs/base/common/objects';
2424
import { DebugStorage } from 'vs/workbench/contrib/debug/common/debugStorage';
2525
import { CancellationTokenSource } from 'vs/base/common/cancellation';
2626

27+
interface IDebugProtocolVariableWithContext extends DebugProtocol.Variable {
28+
__vscodeVariableMenuContext?: string;
29+
}
30+
2731
export class ExpressionContainer implements IExpressionContainer {
2832

2933
public static readonly allValues = new Map<string, string>();
@@ -86,7 +90,7 @@ export class ExpressionContainer implements IExpressionContainer {
8690
for (let i = 0; i < numberOfChunks; i++) {
8791
const start = (this.startOfVariables || 0) + i * chunkSize;
8892
const count = Math.min(chunkSize, this.indexedVariables - i * chunkSize);
89-
children.push(new Variable(this.session, this.threadId, this, this.reference, `[${start}..${start + count - 1}]`, '', '', undefined, count, { kind: 'virtual' }, undefined, true, start));
93+
children.push(new Variable(this.session, this.threadId, this, this.reference, `[${start}..${start + count - 1}]`, '', '', undefined, count, { kind: 'virtual' }, undefined, undefined, true, start));
9094
}
9195

9296
return children;
@@ -117,14 +121,14 @@ export class ExpressionContainer implements IExpressionContainer {
117121
try {
118122
const response = await this.session!.variables(this.reference || 0, this.threadId, filter, start, count);
119123
return response && response.body && response.body.variables
120-
? distinct(response.body.variables.filter(v => !!v), v => v.name).map(v => {
124+
? distinct(response.body.variables.filter(v => !!v), v => v.name).map((v: IDebugProtocolVariableWithContext) => {
121125
if (isString(v.value) && isString(v.name) && typeof v.variablesReference === 'number') {
122-
return new Variable(this.session, this.threadId, this, v.variablesReference, v.name, v.evaluateName, v.value, v.namedVariables, v.indexedVariables, v.presentationHint, v.type);
126+
return new Variable(this.session, this.threadId, this, v.variablesReference, v.name, v.evaluateName, v.value, v.namedVariables, v.indexedVariables, v.presentationHint, v.type, v.__vscodeVariableMenuContext);
123127
}
124-
return new Variable(this.session, this.threadId, this, 0, '', undefined, nls.localize('invalidVariableAttributes', "Invalid variable attributes"), 0, 0, { kind: 'virtual' }, undefined, false);
128+
return new Variable(this.session, this.threadId, this, 0, '', undefined, nls.localize('invalidVariableAttributes', "Invalid variable attributes"), 0, 0, { kind: 'virtual' }, undefined, undefined, false);
125129
}) : [];
126130
} catch (e) {
127-
return [new Variable(this.session, this.threadId, this, 0, '', undefined, e.message, 0, 0, { kind: 'virtual' }, undefined, false)];
131+
return [new Variable(this.session, this.threadId, this, 0, '', undefined, e.message, 0, 0, { kind: 'virtual' }, undefined, undefined, false)];
128132
}
129133
}
130134

@@ -218,6 +222,7 @@ export class Variable extends ExpressionContainer implements IExpression {
218222
indexedVariables: number | undefined,
219223
public presentationHint: DebugProtocol.VariablePresentationHint | undefined,
220224
public type: string | undefined = undefined,
225+
public variableMenuContext: string | undefined = undefined,
221226
public available = true,
222227
startOfVariables = 0
223228
) {

0 commit comments

Comments
 (0)