Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@
{
"command": "java.debug.variables.notShowToString",
"title": "Disable 'toString()' Object View"
},
{
"command": "java.debug.variables.autoExpandLazyVariables",
"title": "Auto Expand Lazy Variables"
},
{
"command": "java.debug.variables.manualExpandLazyVariables",
"title": "Manual Expand Lazy Variables"
}
],
"menus": {
Expand Down Expand Up @@ -295,6 +303,14 @@
{
"command": "java.debug.variables.notShowToString",
"when": "false"
},
{
"command": "java.debug.variables.autoExpandLazyVariables",
"when": "false"
},
{
"command": "java.debug.variables.manualExpandLazyVariables",
"when": "false"
}
],
"debug/variables/context": [
Expand Down Expand Up @@ -339,14 +355,14 @@
"group": "1_view@4"
},
{
"command": "java.debug.variables.showToString",
"when": "debugType == 'java' && javadebug:showToString == 'off'",
"group": "1_view@5"
"command": "java.debug.variables.autoExpandLazyVariables",
"when": "debugType == 'java' && javadebug:expandLazyVariable == 'off'",
"group": "1_view@6"
},
{
"command": "java.debug.variables.notShowToString",
"when": "debugType == 'java' && javadebug:showToString == 'on'",
"group": "1_view@5"
"command": "java.debug.variables.manualExpandLazyVariables",
"when": "debugType == 'java' && javadebug:expandLazyVariable == 'on'",
"group": "1_view@6"
}
]
},
Expand Down
45 changes: 36 additions & 9 deletions src/variableMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w

export function registerVariableMenuCommands(context: vscode.ExtensionContext): void {
vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("java.debug.settings")) {
if (event.affectsConfiguration("java.debug.settings") || event.affectsConfiguration("debug.autoExpandLazyVariables")) {
updateContextKeys();
}
});
Expand All @@ -33,9 +33,20 @@ export function registerVariableMenuCommands(context: vscode.ExtensionContext):
"java.debug.variables.showToString", () => updateVariableFormatter("showToString", true)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
"java.debug.variables.notShowToString", () => updateVariableFormatter("showToString", false)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
"java.debug.variables.autoExpandLazyVariables", () => toggleLazyVariableSetting(true)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(
"java.debug.variables.manualExpandLazyVariables", () => toggleLazyVariableSetting(false)));
}

function updateVariableFormatter(key: string, value: any) {
async function updateVariableFormatter(key: string, value: any) {
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
// Update the formatter to settings.json
await debugSettingsRoot.update(key, value, getConfigurationTarget("java.debug", "settings"));
refreshVariableView();
}

function refreshVariableView() {
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") {
const formatter: any = {
Expand All @@ -45,19 +56,30 @@ function updateVariableFormatter(key: string, value: any) {
showLogicalStructure: debugSettingsRoot.showLogicalStructure,
showToString: debugSettingsRoot.showToString,
};
formatter[key] = value;
vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter);
}
}

async function toggleLazyVariableSetting(toggle: boolean) {
const javadDebugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
if (!javadDebugSettingsRoot.showToString) {
await javadDebugSettingsRoot.update("showToString", true, getConfigurationTarget("java.debug", "settings"));
}

// Update the formatter to settings.json
const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings");
let configurationTarget = vscode.ConfigurationTarget.Global;
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("debug");
await debugSettingsRoot.update("autoExpandLazyVariables", toggle, getConfigurationTarget("debug", "autoExpandLazyVariables"));
refreshVariableView();
}

function getConfigurationTarget(section: string, key: string): vscode.ConfigurationTarget {
const inspect = vscode.workspace.getConfiguration(section).inspect(key);
if (inspect && inspect.workspaceFolderValue !== undefined) {
configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder;
return vscode.ConfigurationTarget.WorkspaceFolder;
} else if (inspect && inspect.workspaceValue !== undefined) {
configurationTarget = vscode.ConfigurationTarget.Workspace;
return vscode.ConfigurationTarget.Workspace;
} else {
return vscode.ConfigurationTarget.Global;
}
debugSettingsRoot.update(key, value, configurationTarget);
}

function updateContextKeys() {
Expand All @@ -69,4 +91,9 @@ function updateContextKeys() {
vscode.commands.executeCommand("setContext", "javadebug:showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off");
vscode.commands.executeCommand("setContext", "javadebug:showToString", debugSettingsRoot.showToString ? "on" : "off");
}

const globalDebugRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("debug");
if (globalDebugRoot) {
vscode.commands.executeCommand("setContext", "javadebug:expandLazyVariable", globalDebugRoot.autoExpandLazyVariables ? "on" : "off");
}
}