diff --git a/package.json b/package.json index 42993d92..0ee08105 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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": [ @@ -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" } ] }, diff --git a/src/variableMenu.ts b/src/variableMenu.ts index 53738ac3..e12889e4 100644 --- a/src/variableMenu.ts +++ b/src/variableMenu.ts @@ -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(); } }); @@ -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 = { @@ -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() { @@ -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"); + } }