|
| 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(instrumentOperationAsVsCodeCommand( |
| 17 | + "java.debug.variables.showHex", () => updateVariableFormatter("showHex", true))); |
| 18 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 19 | + "java.debug.variables.notShowHex", () => updateVariableFormatter("showHex", false))); |
| 20 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 21 | + "java.debug.variables.showQualifiedNames", () => updateVariableFormatter("showQualifiedNames", true))); |
| 22 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 23 | + "java.debug.variables.notShowQualifiedNames", () => updateVariableFormatter("showQualifiedNames", false))); |
| 24 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 25 | + "java.debug.variables.showStaticVariables", () => updateVariableFormatter("showStaticVariables", true))); |
| 26 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 27 | + "java.debug.variables.notShowStaticVariables", () => updateVariableFormatter("showStaticVariables", false))); |
| 28 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 29 | + "java.debug.variables.showLogicalStructure", () => updateVariableFormatter("showLogicalStructure", true))); |
| 30 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 31 | + "java.debug.variables.notShowLogicalStructure", () => updateVariableFormatter("showLogicalStructure", false))); |
| 32 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 33 | + "java.debug.variables.showToString", () => updateVariableFormatter("showToString", true))); |
| 34 | + context.subscriptions.push(instrumentOperationAsVsCodeCommand( |
| 35 | + "java.debug.variables.notShowToString", () => updateVariableFormatter("showToString", false))); |
| 36 | +} |
| 37 | + |
| 38 | +function updateVariableFormatter(key: string, value: any) { |
| 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] = value; |
| 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, value, configurationTarget); |
| 61 | +} |
| 62 | + |
| 63 | +function updateContextKeys() { |
| 64 | + const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); |
| 65 | + if (debugSettingsRoot) { |
| 66 | + vscode.commands.executeCommand("setContext", "javadebug:showHex", debugSettingsRoot.showHex ? "on" : "off"); |
| 67 | + vscode.commands.executeCommand("setContext", "javadebug:showLogicalStructure", debugSettingsRoot.showLogicalStructure ? "on" : "off"); |
| 68 | + vscode.commands.executeCommand("setContext", "javadebug:showQualifiedNames", debugSettingsRoot.showQualifiedNames ? "on" : "off"); |
| 69 | + vscode.commands.executeCommand("setContext", "javadebug:showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off"); |
| 70 | + vscode.commands.executeCommand("setContext", "javadebug:showToString", debugSettingsRoot.showToString ? "on" : "off"); |
| 71 | + } |
| 72 | +} |
0 commit comments