Skip to content

Commit 97aa63b

Browse files
Add menus to VARIABLES view to customize the display styles (#982)
* Add menus to VARIABLES view to customize the display styles
1 parent bed2489 commit 97aa63b

File tree

3 files changed

+206
-0
lines changed

3 files changed

+206
-0
lines changed

package.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,46 @@
9292
{
9393
"command": "java.debug.pauseOthers",
9494
"title": "Pause Others"
95+
},
96+
{
97+
"command": "java.debug.variables.showHex",
98+
"title": "Show as Hex"
99+
},
100+
{
101+
"command": "java.debug.variables.notShowHex",
102+
"title": "Show as Dec"
103+
},
104+
{
105+
"command": "java.debug.variables.showQualifiedNames",
106+
"title": "Show Qualified Names"
107+
},
108+
{
109+
"command": "java.debug.variables.notShowQualifiedNames",
110+
"title": "Show Simple Names"
111+
},
112+
{
113+
"command": "java.debug.variables.showStaticVariables",
114+
"title": "Show Static Variables"
115+
},
116+
{
117+
"command": "java.debug.variables.notShowStaticVariables",
118+
"title": "Hide Static Variables"
119+
},
120+
{
121+
"command": "java.debug.variables.showLogicalStructure",
122+
"title": "Enable Logical Structure View"
123+
},
124+
{
125+
"command": "java.debug.variables.notShowLogicalStructure",
126+
"title": "Disable Logical Structure View"
127+
},
128+
{
129+
"command": "java.debug.variables.showToString",
130+
"title": "Enable 'toString()' Object View"
131+
},
132+
{
133+
"command": "java.debug.variables.notShowToString",
134+
"title": "Disable 'toString()' Object View"
95135
}
96136
],
97137
"menus": {
@@ -209,6 +249,98 @@
209249
{
210250
"command": "java.debug.debugFromProjectView",
211251
"when": "false"
252+
},
253+
{
254+
"command": "java.debug.variables.showHex",
255+
"when": "false"
256+
},
257+
{
258+
"command": "java.debug.variables.notShowHex",
259+
"when": "false"
260+
},
261+
{
262+
"command": "java.debug.variables.showQualifiedNames",
263+
"when": "false"
264+
},
265+
{
266+
"command": "java.debug.variables.notShowQualifiedNames",
267+
"when": "false"
268+
},
269+
{
270+
"command": "java.debug.variables.showStaticVariables",
271+
"when": "false"
272+
},
273+
{
274+
"command": "java.debug.variables.notShowStaticVariables",
275+
"when": "false"
276+
},
277+
{
278+
"command": "java.debug.variables.showLogicalStructure",
279+
"when": "false"
280+
},
281+
{
282+
"command": "java.debug.variables.notShowLogicalStructure",
283+
"when": "false"
284+
},
285+
{
286+
"command": "java.debug.variables.showToString",
287+
"when": "false"
288+
},
289+
{
290+
"command": "java.debug.variables.notShowToString",
291+
"when": "false"
292+
}
293+
],
294+
"debug/variables/context": [
295+
{
296+
"command": "java.debug.variables.showHex",
297+
"when": "debugConfigurationType == 'java' && javadebug:showHex == 'off'",
298+
"group": "1_view@1"
299+
},
300+
{
301+
"command": "java.debug.variables.notShowHex",
302+
"when": "debugConfigurationType == 'java' && javadebug:showHex == 'on'",
303+
"group": "1_view@1"
304+
},
305+
{
306+
"command": "java.debug.variables.showQualifiedNames",
307+
"when": "debugConfigurationType == 'java' && javadebug:showQualifiedNames == 'off'",
308+
"group": "1_view@2"
309+
},
310+
{
311+
"command": "java.debug.variables.notShowQualifiedNames",
312+
"when": "debugConfigurationType == 'java' && javadebug:showQualifiedNames == 'on'",
313+
"group": "1_view@2"
314+
},
315+
{
316+
"command": "java.debug.variables.showStaticVariables",
317+
"when": "debugConfigurationType == 'java' && javadebug:showStaticVariables == 'off'",
318+
"group": "1_view@3"
319+
},
320+
{
321+
"command": "java.debug.variables.notShowStaticVariables",
322+
"when": "debugConfigurationType == 'java' && javadebug:showStaticVariables == 'on'",
323+
"group": "1_view@3"
324+
},
325+
{
326+
"command": "java.debug.variables.showLogicalStructure",
327+
"when": "debugConfigurationType == 'java' && javadebug:showLogicalStructure == 'off'",
328+
"group": "1_view@4"
329+
},
330+
{
331+
"command": "java.debug.variables.notShowLogicalStructure",
332+
"when": "debugConfigurationType == 'java' && javadebug:showLogicalStructure == 'on'",
333+
"group": "1_view@4"
334+
},
335+
{
336+
"command": "java.debug.variables.showToString",
337+
"when": "debugConfigurationType == 'java' && javadebug:showToString == 'off'",
338+
"group": "1_view@5"
339+
},
340+
{
341+
"command": "java.debug.variables.notShowToString",
342+
"when": "debugConfigurationType == 'java' && javadebug:showToString == 'on'",
343+
"group": "1_view@5"
212344
}
213345
]
214346
},

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { progressProvider } from "./progressImpl";
2626
import { JavaTerminalLinkProvder } from "./terminalLinkProvider";
2727
import { initializeThreadOperations } from "./threadOperations";
2828
import * as utility from "./utility";
29+
import { registerVariableMenuCommands } from "./variableMenu";
2930

3031
export async function activate(context: vscode.ExtensionContext): Promise<any> {
3132
await initializeFromJsonFile(context.asAbsolutePath("./package.json"), {
@@ -40,6 +41,7 @@ function initializeExtension(_operationId: string, context: vscode.ExtensionCont
4041
logger.initialize(context, true);
4142

4243
registerDebugEventListener(context);
44+
registerVariableMenuCommands(context);
4345
context.subscriptions.push(logger);
4446
context.subscriptions.push(vscode.window.registerTerminalLinkProvider(new JavaTerminalLinkProvder()));
4547
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider()));

src/variableMenu.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import * as vscode from "vscode";
5+
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
6+
7+
export function registerVariableMenuCommands(context: vscode.ExtensionContext): void {
8+
vscode.workspace.onDidChangeConfiguration((event) => {
9+
if (event.affectsConfiguration("java.debug.settings")) {
10+
updateContextKeys();
11+
}
12+
});
13+
// Initialize the context keys
14+
updateContextKeys();
15+
16+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
17+
"java.debug.variables.showHex", () => updateVariableFormatter("showHex", true)));
18+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
19+
"java.debug.variables.notShowHex", () => updateVariableFormatter("showHex", false)));
20+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
21+
"java.debug.variables.showQualifiedNames", () => updateVariableFormatter("showQualifiedNames", true)));
22+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
23+
"java.debug.variables.notShowQualifiedNames", () => updateVariableFormatter("showQualifiedNames", false)));
24+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
25+
"java.debug.variables.showStaticVariables", () => updateVariableFormatter("showStaticVariables", true)));
26+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
27+
"java.debug.variables.notShowStaticVariables", () => updateVariableFormatter("showStaticVariables", false)));
28+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
29+
"java.debug.variables.showLogicalStructure", () => updateVariableFormatter("showLogicalStructure", true)));
30+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
31+
"java.debug.variables.notShowLogicalStructure", () => updateVariableFormatter("showLogicalStructure", false)));
32+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
33+
"java.debug.variables.showToString", () => updateVariableFormatter("showToString", true)));
34+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
35+
"java.debug.variables.notShowToString", () => updateVariableFormatter("showToString", false)));
36+
}
37+
38+
function updateVariableFormatter(key: string, value: any) {
39+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
40+
if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") {
41+
const formatter: any = {
42+
showHex: debugSettingsRoot.showHex,
43+
showQualifiedNames: debugSettingsRoot.showQualifiedNames,
44+
showStaticVariables: debugSettingsRoot.showStaticVariables,
45+
showLogicalStructure: debugSettingsRoot.showLogicalStructure,
46+
showToString: debugSettingsRoot.showToString,
47+
};
48+
formatter[key] = value;
49+
vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter);
50+
}
51+
52+
// Update the formatter to settings.json
53+
const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings");
54+
let configurationTarget = vscode.ConfigurationTarget.Global;
55+
if (inspect && inspect.workspaceFolderValue !== undefined) {
56+
configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder;
57+
} else if (inspect && inspect.workspaceValue !== undefined) {
58+
configurationTarget = vscode.ConfigurationTarget.Workspace;
59+
}
60+
debugSettingsRoot.update(key, value, configurationTarget);
61+
}
62+
63+
function updateContextKeys() {
64+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
65+
if (debugSettingsRoot) {
66+
vscode.commands.executeCommand("setContext", "javadebug:showHex", debugSettingsRoot.showHex ? "on" : "off");
67+
vscode.commands.executeCommand("setContext", "javadebug:showLogicalStructure", debugSettingsRoot.showLogicalStructure ? "on" : "off");
68+
vscode.commands.executeCommand("setContext", "javadebug:showQualifiedNames", debugSettingsRoot.showQualifiedNames ? "on" : "off");
69+
vscode.commands.executeCommand("setContext", "javadebug:showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off");
70+
vscode.commands.executeCommand("setContext", "javadebug:showToString", debugSettingsRoot.showToString ? "on" : "off");
71+
}
72+
}

0 commit comments

Comments
 (0)