@@ -6,7 +6,7 @@ import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-w
66
77export 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
6385function 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