Skip to content

Commit 6aad3fc

Browse files
Add menus to VARIABLES view to customize the display styles
1 parent 21c9f1a commit 6aad3fc

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-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' && java.debug.showHex == 'off'",
298+
"group": "1_view@1"
299+
},
300+
{
301+
"command": "java.debug.variables.notShowHex",
302+
"when": "debugConfigurationType == 'java' && java.debug.showHex == 'on'",
303+
"group": "1_view@1"
304+
},
305+
{
306+
"command": "java.debug.variables.showQualifiedNames",
307+
"when": "debugConfigurationType == 'java' && java.debug.showQualifiedNames == 'off'",
308+
"group": "1_view@2"
309+
},
310+
{
311+
"command": "java.debug.variables.notShowQualifiedNames",
312+
"when": "debugConfigurationType == 'java' && java.debug.showQualifiedNames == 'on'",
313+
"group": "1_view@2"
314+
},
315+
{
316+
"command": "java.debug.variables.showStaticVariables",
317+
"when": "debugConfigurationType == 'java' && java.debug.showStaticVariables == 'off'",
318+
"group": "1_view@3"
319+
},
320+
{
321+
"command": "java.debug.variables.notShowStaticVariables",
322+
"when": "debugConfigurationType == 'java' && java.debug.showStaticVariables == 'on'",
323+
"group": "1_view@3"
324+
},
325+
{
326+
"command": "java.debug.variables.showLogicalStructure",
327+
"when": "debugConfigurationType == 'java' && java.debug.showLogicalStructure == 'off'",
328+
"group": "1_view@4"
329+
},
330+
{
331+
"command": "java.debug.variables.notShowLogicalStructure",
332+
"when": "debugConfigurationType == 'java' && java.debug.showLogicalStructure == 'on'",
333+
"group": "1_view@4"
334+
},
335+
{
336+
"command": "java.debug.variables.showToString",
337+
"when": "debugConfigurationType == 'java' && java.debug.showToString == 'off'",
338+
"group": "1_view@5"
339+
},
340+
{
341+
"command": "java.debug.variables.notShowToString",
342+
"when": "debugConfigurationType == 'java' && java.debug.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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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(
17+
instrumentOperationAsVsCodeCommand("java.debug.variables.showHex", () => turnOnFormat("showHex")));
18+
context.subscriptions.push(
19+
instrumentOperationAsVsCodeCommand("java.debug.variables.notShowHex", () => turnOffFormat("showHex")));
20+
context.subscriptions.push(
21+
instrumentOperationAsVsCodeCommand("java.debug.variables.showQualifiedNames", () => turnOnFormat("showQualifiedNames")));
22+
context.subscriptions.push(
23+
instrumentOperationAsVsCodeCommand("java.debug.variables.notShowQualifiedNames", () => turnOffFormat("showQualifiedNames")));
24+
context.subscriptions.push(
25+
instrumentOperationAsVsCodeCommand("java.debug.variables.showStaticVariables", () => turnOnFormat("showStaticVariables")));
26+
context.subscriptions.push(
27+
instrumentOperationAsVsCodeCommand("java.debug.variables.notShowStaticVariables", () => turnOffFormat("showStaticVariables")));
28+
context.subscriptions.push(
29+
instrumentOperationAsVsCodeCommand("java.debug.variables.showLogicalStructure", () => turnOnFormat("showLogicalStructure")));
30+
context.subscriptions.push(
31+
instrumentOperationAsVsCodeCommand("java.debug.variables.notShowLogicalStructure", () => turnOffFormat("showLogicalStructure")));
32+
context.subscriptions.push(
33+
instrumentOperationAsVsCodeCommand("java.debug.variables.showToString", () => turnOnFormat("showToString")));
34+
context.subscriptions.push(
35+
instrumentOperationAsVsCodeCommand("java.debug.variables.notShowToString", () => turnOffFormat("showToString")));
36+
}
37+
38+
function turnOnFormat(key: string) {
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] = true;
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, true, configurationTarget);
61+
}
62+
63+
function turnOffFormat(key: string) {
64+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
65+
if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") {
66+
const formatter: any = {
67+
showHex: debugSettingsRoot.showHex,
68+
showQualifiedNames: debugSettingsRoot.showQualifiedNames,
69+
showStaticVariables: debugSettingsRoot.showStaticVariables,
70+
showLogicalStructure: debugSettingsRoot.showLogicalStructure,
71+
showToString: debugSettingsRoot.showToString,
72+
};
73+
formatter[key] = false;
74+
vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter);
75+
}
76+
77+
// Update the formatter to settings.json
78+
const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings");
79+
let configurationTarget = vscode.ConfigurationTarget.Global;
80+
if (inspect && inspect.workspaceFolderValue !== undefined) {
81+
configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder;
82+
} else if (inspect && inspect.workspaceValue !== undefined) {
83+
configurationTarget = vscode.ConfigurationTarget.Workspace;
84+
}
85+
debugSettingsRoot.update(key, false, configurationTarget);
86+
}
87+
88+
function updateContextKeys() {
89+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
90+
if (debugSettingsRoot) {
91+
vscode.commands.executeCommand("setContext", "java.debug.showHex", debugSettingsRoot.showHex ? "on" : "off");
92+
vscode.commands.executeCommand("setContext", "java.debug.showLogicalStructure", debugSettingsRoot.showLogicalStructure ? "on" : "off");
93+
vscode.commands.executeCommand("setContext", "java.debug.showQualifiedNames", debugSettingsRoot.showQualifiedNames ? "on" : "off");
94+
vscode.commands.executeCommand("setContext", "java.debug.showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off");
95+
vscode.commands.executeCommand("setContext", "java.debug.showToString", debugSettingsRoot.showToString ? "on" : "off");
96+
return;
97+
}
98+
}

0 commit comments

Comments
 (0)