From 6aad3fc941aa08e02e8ea81bc3b370203265fb73 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 21 Apr 2021 10:27:10 +0800 Subject: [PATCH 1/2] Add menus to VARIABLES view to customize the display styles --- package.json | 132 ++++++++++++++++++++++++++++++++++++++++++++ src/extension.ts | 2 + src/variableMenu.ts | 98 ++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 src/variableMenu.ts diff --git a/package.json b/package.json index 3a17c5d2..a473250d 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,46 @@ { "command": "java.debug.pauseOthers", "title": "Pause Others" + }, + { + "command": "java.debug.variables.showHex", + "title": "Show as Hex" + }, + { + "command": "java.debug.variables.notShowHex", + "title": "Show as Dec" + }, + { + "command": "java.debug.variables.showQualifiedNames", + "title": "Show Qualified Names" + }, + { + "command": "java.debug.variables.notShowQualifiedNames", + "title": "Show Simple Names" + }, + { + "command": "java.debug.variables.showStaticVariables", + "title": "Show Static Variables" + }, + { + "command": "java.debug.variables.notShowStaticVariables", + "title": "Hide Static Variables" + }, + { + "command": "java.debug.variables.showLogicalStructure", + "title": "Enable Logical Structure View" + }, + { + "command": "java.debug.variables.notShowLogicalStructure", + "title": "Disable Logical Structure View" + }, + { + "command": "java.debug.variables.showToString", + "title": "Enable 'toString()' Object View" + }, + { + "command": "java.debug.variables.notShowToString", + "title": "Disable 'toString()' Object View" } ], "menus": { @@ -209,6 +249,98 @@ { "command": "java.debug.debugFromProjectView", "when": "false" + }, + { + "command": "java.debug.variables.showHex", + "when": "false" + }, + { + "command": "java.debug.variables.notShowHex", + "when": "false" + }, + { + "command": "java.debug.variables.showQualifiedNames", + "when": "false" + }, + { + "command": "java.debug.variables.notShowQualifiedNames", + "when": "false" + }, + { + "command": "java.debug.variables.showStaticVariables", + "when": "false" + }, + { + "command": "java.debug.variables.notShowStaticVariables", + "when": "false" + }, + { + "command": "java.debug.variables.showLogicalStructure", + "when": "false" + }, + { + "command": "java.debug.variables.notShowLogicalStructure", + "when": "false" + }, + { + "command": "java.debug.variables.showToString", + "when": "false" + }, + { + "command": "java.debug.variables.notShowToString", + "when": "false" + } + ], + "debug/variables/context": [ + { + "command": "java.debug.variables.showHex", + "when": "debugConfigurationType == 'java' && java.debug.showHex == 'off'", + "group": "1_view@1" + }, + { + "command": "java.debug.variables.notShowHex", + "when": "debugConfigurationType == 'java' && java.debug.showHex == 'on'", + "group": "1_view@1" + }, + { + "command": "java.debug.variables.showQualifiedNames", + "when": "debugConfigurationType == 'java' && java.debug.showQualifiedNames == 'off'", + "group": "1_view@2" + }, + { + "command": "java.debug.variables.notShowQualifiedNames", + "when": "debugConfigurationType == 'java' && java.debug.showQualifiedNames == 'on'", + "group": "1_view@2" + }, + { + "command": "java.debug.variables.showStaticVariables", + "when": "debugConfigurationType == 'java' && java.debug.showStaticVariables == 'off'", + "group": "1_view@3" + }, + { + "command": "java.debug.variables.notShowStaticVariables", + "when": "debugConfigurationType == 'java' && java.debug.showStaticVariables == 'on'", + "group": "1_view@3" + }, + { + "command": "java.debug.variables.showLogicalStructure", + "when": "debugConfigurationType == 'java' && java.debug.showLogicalStructure == 'off'", + "group": "1_view@4" + }, + { + "command": "java.debug.variables.notShowLogicalStructure", + "when": "debugConfigurationType == 'java' && java.debug.showLogicalStructure == 'on'", + "group": "1_view@4" + }, + { + "command": "java.debug.variables.showToString", + "when": "debugConfigurationType == 'java' && java.debug.showToString == 'off'", + "group": "1_view@5" + }, + { + "command": "java.debug.variables.notShowToString", + "when": "debugConfigurationType == 'java' && java.debug.showToString == 'on'", + "group": "1_view@5" } ] }, diff --git a/src/extension.ts b/src/extension.ts index c2e4570f..0d11d2f9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -26,6 +26,7 @@ import { progressProvider } from "./progressImpl"; import { JavaTerminalLinkProvder } from "./terminalLinkProvider"; import { initializeThreadOperations } from "./threadOperations"; import * as utility from "./utility"; +import { registerVariableMenuCommands } from "./variableMenu"; export async function activate(context: vscode.ExtensionContext): Promise { await initializeFromJsonFile(context.asAbsolutePath("./package.json"), { @@ -40,6 +41,7 @@ function initializeExtension(_operationId: string, context: vscode.ExtensionCont logger.initialize(context, true); registerDebugEventListener(context); + registerVariableMenuCommands(context); context.subscriptions.push(logger); context.subscriptions.push(vscode.window.registerTerminalLinkProvider(new JavaTerminalLinkProvder())); context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider())); diff --git a/src/variableMenu.ts b/src/variableMenu.ts new file mode 100644 index 00000000..33fd750a --- /dev/null +++ b/src/variableMenu.ts @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +import * as vscode from "vscode"; +import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper"; + +export function registerVariableMenuCommands(context: vscode.ExtensionContext): void { + vscode.workspace.onDidChangeConfiguration((event) => { + if (event.affectsConfiguration("java.debug.settings")) { + updateContextKeys(); + } + }); + // Initialize the context keys + updateContextKeys(); + + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.showHex", () => turnOnFormat("showHex"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.notShowHex", () => turnOffFormat("showHex"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.showQualifiedNames", () => turnOnFormat("showQualifiedNames"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.notShowQualifiedNames", () => turnOffFormat("showQualifiedNames"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.showStaticVariables", () => turnOnFormat("showStaticVariables"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.notShowStaticVariables", () => turnOffFormat("showStaticVariables"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.showLogicalStructure", () => turnOnFormat("showLogicalStructure"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.notShowLogicalStructure", () => turnOffFormat("showLogicalStructure"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.showToString", () => turnOnFormat("showToString"))); + context.subscriptions.push( + instrumentOperationAsVsCodeCommand("java.debug.variables.notShowToString", () => turnOffFormat("showToString"))); +} + +function turnOnFormat(key: string) { + const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); + if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") { + const formatter: any = { + showHex: debugSettingsRoot.showHex, + showQualifiedNames: debugSettingsRoot.showQualifiedNames, + showStaticVariables: debugSettingsRoot.showStaticVariables, + showLogicalStructure: debugSettingsRoot.showLogicalStructure, + showToString: debugSettingsRoot.showToString, + }; + formatter[key] = true; + vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter); + } + + // Update the formatter to settings.json + const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings"); + let configurationTarget = vscode.ConfigurationTarget.Global; + if (inspect && inspect.workspaceFolderValue !== undefined) { + configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder; + } else if (inspect && inspect.workspaceValue !== undefined) { + configurationTarget = vscode.ConfigurationTarget.Workspace; + } + debugSettingsRoot.update(key, true, configurationTarget); +} + +function turnOffFormat(key: string) { + const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); + if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") { + const formatter: any = { + showHex: debugSettingsRoot.showHex, + showQualifiedNames: debugSettingsRoot.showQualifiedNames, + showStaticVariables: debugSettingsRoot.showStaticVariables, + showLogicalStructure: debugSettingsRoot.showLogicalStructure, + showToString: debugSettingsRoot.showToString, + }; + formatter[key] = false; + vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter); + } + + // Update the formatter to settings.json + const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings"); + let configurationTarget = vscode.ConfigurationTarget.Global; + if (inspect && inspect.workspaceFolderValue !== undefined) { + configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder; + } else if (inspect && inspect.workspaceValue !== undefined) { + configurationTarget = vscode.ConfigurationTarget.Workspace; + } + debugSettingsRoot.update(key, false, configurationTarget); +} + +function updateContextKeys() { + const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); + if (debugSettingsRoot) { + vscode.commands.executeCommand("setContext", "java.debug.showHex", debugSettingsRoot.showHex ? "on" : "off"); + vscode.commands.executeCommand("setContext", "java.debug.showLogicalStructure", debugSettingsRoot.showLogicalStructure ? "on" : "off"); + vscode.commands.executeCommand("setContext", "java.debug.showQualifiedNames", debugSettingsRoot.showQualifiedNames ? "on" : "off"); + vscode.commands.executeCommand("setContext", "java.debug.showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off"); + vscode.commands.executeCommand("setContext", "java.debug.showToString", debugSettingsRoot.showToString ? "on" : "off"); + return; + } +} From f478d2524926f13a3d8f292f3e0e2bb083e6d87d Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 21 Apr 2021 13:58:54 +0800 Subject: [PATCH 2/2] address review comments --- package.json | 20 +++++------ src/variableMenu.ts | 82 ++++++++++++++++----------------------------- 2 files changed, 38 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index a473250d..f97728bc 100644 --- a/package.json +++ b/package.json @@ -294,52 +294,52 @@ "debug/variables/context": [ { "command": "java.debug.variables.showHex", - "when": "debugConfigurationType == 'java' && java.debug.showHex == 'off'", + "when": "debugConfigurationType == 'java' && javadebug:showHex == 'off'", "group": "1_view@1" }, { "command": "java.debug.variables.notShowHex", - "when": "debugConfigurationType == 'java' && java.debug.showHex == 'on'", + "when": "debugConfigurationType == 'java' && javadebug:showHex == 'on'", "group": "1_view@1" }, { "command": "java.debug.variables.showQualifiedNames", - "when": "debugConfigurationType == 'java' && java.debug.showQualifiedNames == 'off'", + "when": "debugConfigurationType == 'java' && javadebug:showQualifiedNames == 'off'", "group": "1_view@2" }, { "command": "java.debug.variables.notShowQualifiedNames", - "when": "debugConfigurationType == 'java' && java.debug.showQualifiedNames == 'on'", + "when": "debugConfigurationType == 'java' && javadebug:showQualifiedNames == 'on'", "group": "1_view@2" }, { "command": "java.debug.variables.showStaticVariables", - "when": "debugConfigurationType == 'java' && java.debug.showStaticVariables == 'off'", + "when": "debugConfigurationType == 'java' && javadebug:showStaticVariables == 'off'", "group": "1_view@3" }, { "command": "java.debug.variables.notShowStaticVariables", - "when": "debugConfigurationType == 'java' && java.debug.showStaticVariables == 'on'", + "when": "debugConfigurationType == 'java' && javadebug:showStaticVariables == 'on'", "group": "1_view@3" }, { "command": "java.debug.variables.showLogicalStructure", - "when": "debugConfigurationType == 'java' && java.debug.showLogicalStructure == 'off'", + "when": "debugConfigurationType == 'java' && javadebug:showLogicalStructure == 'off'", "group": "1_view@4" }, { "command": "java.debug.variables.notShowLogicalStructure", - "when": "debugConfigurationType == 'java' && java.debug.showLogicalStructure == 'on'", + "when": "debugConfigurationType == 'java' && javadebug:showLogicalStructure == 'on'", "group": "1_view@4" }, { "command": "java.debug.variables.showToString", - "when": "debugConfigurationType == 'java' && java.debug.showToString == 'off'", + "when": "debugConfigurationType == 'java' && javadebug:showToString == 'off'", "group": "1_view@5" }, { "command": "java.debug.variables.notShowToString", - "when": "debugConfigurationType == 'java' && java.debug.showToString == 'on'", + "when": "debugConfigurationType == 'java' && javadebug:showToString == 'on'", "group": "1_view@5" } ] diff --git a/src/variableMenu.ts b/src/variableMenu.ts index 33fd750a..53738ac3 100644 --- a/src/variableMenu.ts +++ b/src/variableMenu.ts @@ -13,29 +13,29 @@ export function registerVariableMenuCommands(context: vscode.ExtensionContext): // Initialize the context keys updateContextKeys(); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.showHex", () => turnOnFormat("showHex"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.notShowHex", () => turnOffFormat("showHex"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.showQualifiedNames", () => turnOnFormat("showQualifiedNames"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.notShowQualifiedNames", () => turnOffFormat("showQualifiedNames"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.showStaticVariables", () => turnOnFormat("showStaticVariables"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.notShowStaticVariables", () => turnOffFormat("showStaticVariables"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.showLogicalStructure", () => turnOnFormat("showLogicalStructure"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.notShowLogicalStructure", () => turnOffFormat("showLogicalStructure"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.showToString", () => turnOnFormat("showToString"))); - context.subscriptions.push( - instrumentOperationAsVsCodeCommand("java.debug.variables.notShowToString", () => turnOffFormat("showToString"))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.showHex", () => updateVariableFormatter("showHex", true))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.notShowHex", () => updateVariableFormatter("showHex", false))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.showQualifiedNames", () => updateVariableFormatter("showQualifiedNames", true))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.notShowQualifiedNames", () => updateVariableFormatter("showQualifiedNames", false))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.showStaticVariables", () => updateVariableFormatter("showStaticVariables", true))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.notShowStaticVariables", () => updateVariableFormatter("showStaticVariables", false))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.showLogicalStructure", () => updateVariableFormatter("showLogicalStructure", true))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.notShowLogicalStructure", () => updateVariableFormatter("showLogicalStructure", false))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.showToString", () => updateVariableFormatter("showToString", true))); + context.subscriptions.push(instrumentOperationAsVsCodeCommand( + "java.debug.variables.notShowToString", () => updateVariableFormatter("showToString", false))); } -function turnOnFormat(key: string) { +function updateVariableFormatter(key: string, value: any) { const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") { const formatter: any = { @@ -45,7 +45,7 @@ function turnOnFormat(key: string) { showLogicalStructure: debugSettingsRoot.showLogicalStructure, showToString: debugSettingsRoot.showToString, }; - formatter[key] = true; + formatter[key] = value; vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter); } @@ -57,42 +57,16 @@ function turnOnFormat(key: string) { } else if (inspect && inspect.workspaceValue !== undefined) { configurationTarget = vscode.ConfigurationTarget.Workspace; } - debugSettingsRoot.update(key, true, configurationTarget); -} - -function turnOffFormat(key: string) { - const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); - if (vscode.debug.activeDebugSession && vscode.debug.activeDebugSession.type === "java") { - const formatter: any = { - showHex: debugSettingsRoot.showHex, - showQualifiedNames: debugSettingsRoot.showQualifiedNames, - showStaticVariables: debugSettingsRoot.showStaticVariables, - showLogicalStructure: debugSettingsRoot.showLogicalStructure, - showToString: debugSettingsRoot.showToString, - }; - formatter[key] = false; - vscode.debug.activeDebugSession.customRequest("refreshVariables", formatter); - } - - // Update the formatter to settings.json - const inspect = vscode.workspace.getConfiguration("java.debug").inspect("settings"); - let configurationTarget = vscode.ConfigurationTarget.Global; - if (inspect && inspect.workspaceFolderValue !== undefined) { - configurationTarget = vscode.ConfigurationTarget.WorkspaceFolder; - } else if (inspect && inspect.workspaceValue !== undefined) { - configurationTarget = vscode.ConfigurationTarget.Workspace; - } - debugSettingsRoot.update(key, false, configurationTarget); + debugSettingsRoot.update(key, value, configurationTarget); } function updateContextKeys() { const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings"); if (debugSettingsRoot) { - vscode.commands.executeCommand("setContext", "java.debug.showHex", debugSettingsRoot.showHex ? "on" : "off"); - vscode.commands.executeCommand("setContext", "java.debug.showLogicalStructure", debugSettingsRoot.showLogicalStructure ? "on" : "off"); - vscode.commands.executeCommand("setContext", "java.debug.showQualifiedNames", debugSettingsRoot.showQualifiedNames ? "on" : "off"); - vscode.commands.executeCommand("setContext", "java.debug.showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off"); - vscode.commands.executeCommand("setContext", "java.debug.showToString", debugSettingsRoot.showToString ? "on" : "off"); - return; + vscode.commands.executeCommand("setContext", "javadebug:showHex", debugSettingsRoot.showHex ? "on" : "off"); + vscode.commands.executeCommand("setContext", "javadebug:showLogicalStructure", debugSettingsRoot.showLogicalStructure ? "on" : "off"); + vscode.commands.executeCommand("setContext", "javadebug:showQualifiedNames", debugSettingsRoot.showQualifiedNames ? "on" : "off"); + vscode.commands.executeCommand("setContext", "javadebug:showStaticVariables", debugSettingsRoot.showStaticVariables ? "on" : "off"); + vscode.commands.executeCommand("setContext", "javadebug:showToString", debugSettingsRoot.showToString ? "on" : "off"); } }