Skip to content

Commit 840eab9

Browse files
Add context menus to Variables view to auto show 'toString()' value (#1316)
1 parent f6a5aa9 commit 840eab9

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

package.json

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@
138138
{
139139
"command": "java.debug.variables.notShowToString",
140140
"title": "Disable 'toString()' Object View"
141+
},
142+
{
143+
"command": "java.debug.variables.autoExpandLazyVariables",
144+
"title": "Auto Expand Lazy Variables"
145+
},
146+
{
147+
"command": "java.debug.variables.manualExpandLazyVariables",
148+
"title": "Manual Expand Lazy Variables"
141149
}
142150
],
143151
"menus": {
@@ -295,6 +303,14 @@
295303
{
296304
"command": "java.debug.variables.notShowToString",
297305
"when": "false"
306+
},
307+
{
308+
"command": "java.debug.variables.autoExpandLazyVariables",
309+
"when": "false"
310+
},
311+
{
312+
"command": "java.debug.variables.manualExpandLazyVariables",
313+
"when": "false"
298314
}
299315
],
300316
"debug/variables/context": [
@@ -339,14 +355,14 @@
339355
"group": "1_view@4"
340356
},
341357
{
342-
"command": "java.debug.variables.showToString",
343-
"when": "debugType == 'java' && javadebug:showToString == 'off'",
344-
"group": "1_view@5"
358+
"command": "java.debug.variables.autoExpandLazyVariables",
359+
"when": "debugType == 'java' && javadebug:expandLazyVariable == 'off'",
360+
"group": "1_view@6"
345361
},
346362
{
347-
"command": "java.debug.variables.notShowToString",
348-
"when": "debugType == 'java' && javadebug:showToString == 'on'",
349-
"group": "1_view@5"
363+
"command": "java.debug.variables.manualExpandLazyVariables",
364+
"when": "debugType == 'java' && javadebug:expandLazyVariable == 'on'",
365+
"group": "1_view@6"
350366
}
351367
]
352368
},

src/variableMenu.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w
66

77
export function registerVariableMenuCommands(context: vscode.ExtensionContext): void {
88
vscode.workspace.onDidChangeConfiguration((event) => {
9-
if (event.affectsConfiguration("java.debug.settings")) {
9+
if (event.affectsConfiguration("java.debug.settings") || event.affectsConfiguration("debug.autoExpandLazyVariables")) {
1010
updateContextKeys();
1111
}
1212
});
@@ -33,9 +33,20 @@ export function registerVariableMenuCommands(context: vscode.ExtensionContext):
3333
"java.debug.variables.showToString", () => updateVariableFormatter("showToString", true)));
3434
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
3535
"java.debug.variables.notShowToString", () => updateVariableFormatter("showToString", false)));
36+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
37+
"java.debug.variables.autoExpandLazyVariables", () => toggleLazyVariableSetting(true)));
38+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
39+
"java.debug.variables.manualExpandLazyVariables", () => toggleLazyVariableSetting(false)));
3640
}
3741

38-
function updateVariableFormatter(key: string, value: any) {
42+
async function updateVariableFormatter(key: string, value: any) {
43+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
44+
// Update the formatter to settings.json
45+
await debugSettingsRoot.update(key, value, getConfigurationTarget("java.debug", "settings"));
46+
refreshVariableView();
47+
}
48+
49+
function refreshVariableView() {
3950
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
4051
if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") {
4152
const formatter: any = {
@@ -45,19 +56,30 @@ function updateVariableFormatter(key: string, value: any) {
4556
showLogicalStructure: debugSettingsRoot.showLogicalStructure,
4657
showToString: debugSettingsRoot.showToString,
4758
};
48-
formatter[key] = value;
4959
vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter);
5060
}
61+
}
62+
63+
async function toggleLazyVariableSetting(toggle: boolean) {
64+
const javadDebugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
65+
if (!javadDebugSettingsRoot.showToString) {
66+
await javadDebugSettingsRoot.update("showToString", true, getConfigurationTarget("java.debug", "settings"));
67+
}
5168

52-
// Update the formatter to settings.json
53-
const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings");
54-
let configurationTarget = vscode.ConfigurationTarget.Global;
69+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("debug");
70+
await debugSettingsRoot.update("autoExpandLazyVariables", toggle, getConfigurationTarget("debug", "autoExpandLazyVariables"));
71+
refreshVariableView();
72+
}
73+
74+
function getConfigurationTarget(section: string, key: string): vscode.ConfigurationTarget {
75+
const inspect = vscode.workspace.getConfiguration(section).inspect(key);
5576
if (inspect && inspect.workspaceFolderValue !== undefined) {
56-
configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder;
77+
return vscode.ConfigurationTarget.WorkspaceFolder;
5778
} else if (inspect && inspect.workspaceValue !== undefined) {
58-
configurationTarget = vscode.ConfigurationTarget.Workspace;
79+
return vscode.ConfigurationTarget.Workspace;
80+
} else {
81+
return vscode.ConfigurationTarget.Global;
5982
}
60-
debugSettingsRoot.update(key, value, configurationTarget);
6183
}
6284

6385
function updateContextKeys() {
@@ -69,4 +91,9 @@ function updateContextKeys() {
6991
vscode.commands.executeCommand("setContext", "javadebug:showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off");
7092
vscode.commands.executeCommand("setContext", "javadebug:showToString", debugSettingsRoot.showToString ? "on" : "off");
7193
}
94+
95+
const globalDebugRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("debug");
96+
if (globalDebugRoot) {
97+
vscode.commands.executeCommand("setContext", "javadebug:expandLazyVariable", globalDebugRoot.autoExpandLazyVariables ? "on" : "off");
98+
}
7299
}

0 commit comments

Comments
 (0)