From d6388a78fa5a74920ba65b5f59898f6d56b5158e Mon Sep 17 00:00:00 2001 From: andxu Date: Tue, 7 Nov 2017 17:29:22 +0800 Subject: [PATCH 1/8] 1. watch user settings for changed event, apply it when change happens 2. get debug settings from user settings and send it to debuggee --- README.md | 4 +++ package.json | 16 +++++++++ src/commands.ts | 2 ++ src/configurationProvider.ts | 69 ++++++++++++++++++++++++++++++++---- 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a7428b54..26f4e3d2 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht ### User Settings - `java.debug.logLevel`: minimum level of debugger logs that are sent to VS Code, defaults to `warn`. +- `java.debug.settings.showHex`: whether or not the number should be displayed as hex format in variable view, defaults to `false`. +- `java.debug.settings.showStaticVariables`: whether or not the static variables will be displayed in variable view, defaults to `true`. +- `java.debug.settings.showQualifiedNames`: whether or not the class name should be displayed using the fully qualified class name, defaults to `false`. +- `java.debug.settings.maxStringLength`: the maximum length of string displayed in variable view/console, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed. ## Feedback and Questions You can find the full list of issues at [Issue Tracker](https://github.com/Microsoft/vscode-java-debug/issues). You can submit a [bug or feature suggestion](https://github.com/Microsoft/vscode-java-debug/issues/new), and participate community driven [![Gitter](https://badges.gitter.im/Microsoft/vscode-java-debug.svg)](https://gitter.im/Microsoft/vscode-java-debug) diff --git a/package.json b/package.json index 34fbd3df..c76727e0 100644 --- a/package.json +++ b/package.json @@ -190,6 +190,22 @@ "info", "verbose" ] + }, + "java.debug.settings.showHex": { + "type": "boolean", + "default": false + }, + "java.debug.settings.showStaticVariables": { + "type": "boolean", + "default": true + }, + "java.debug.settings.showQualifiedNames": { + "type": "boolean", + "default": false + }, + "java.debug.settings.maxStringLength": { + "type": "number", + "default": 0 } } } diff --git a/src/commands.ts b/src/commands.ts index 44f6aff1..3e08c55e 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -21,6 +21,8 @@ export const JAVA_FETCH_USAGE_DATA = "vscode.java.fetchUsageData"; export const JAVA_CONFIG_LOG_LEVEL = "vscode.java.configLogLevel"; +export const JAVA_UPDATE_DEBUG_SETTINGS = "vscode.java.updateDebugSettings"; + export function executeJavaLanguageServerCommand(...rest) { // TODO: need to handle error and trace telemetry return vscode.commands.executeCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest); diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index b31c93ff..caf4db54 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -6,7 +6,16 @@ import TelemetryReporter from "vscode-extension-telemetry"; import * as commands from "./commands"; export class JavaDebugConfigurationProvider implements vscode.DebugConfigurationProvider { + private isUserSettingsDirty: boolean = true; constructor(private _reporter: TelemetryReporter) { + vscode.workspace.onDidChangeConfiguration((event) => { + if (vscode.debug.activeDebugSession) { + this.isUserSettingsDirty = false; + return updateUserSettings(); + } else { + this.isUserSettingsDirty = true; + } + }); } // Returns an initial debug configurations based on contextual information. @@ -72,12 +81,9 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration private async heuristicallyResolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration) { try { - try { - const level = await configLogLevel(vscode.workspace.getConfiguration().get("java.debug.logLevel")); - console.log("setting log level to ", level); - } catch (err) { - // log a warning message and continue, since logger failure should not block debug session - console.log("Cannot set log level to java debuggeer.") + if (this.isUserSettingsDirty) { + this.isUserSettingsDirty = false; + await updateUserSettings(); } // trigger build workspace @@ -216,6 +222,57 @@ function configLogLevel(level) { return commands.executeJavaLanguageServerCommand(commands.JAVA_CONFIG_LOG_LEVEL, convertLogLevel(level)); } +interface IDebugSettings { + show_hex?: boolean; + show_static_variables?: boolean; + show_qualified_names?: boolean; + max_string_length?: number; +} + +async function updateDebugSettings() { + const settings: IDebugSettings = collectDebugSettings(); + if (settings && Object.keys(settings).length) { + console.log("settings:", await commands.executeJavaLanguageServerCommand(commands.JAVA_UPDATE_DEBUG_SETTINGS, JSON.stringify(settings))); + } +} + +async function updateUserSettings() { + try { + const level = await configLogLevel(vscode.workspace.getConfiguration().get("java.debug.logLevel")); + console.log("setting log level to ", level); + } catch (err) { + // log a warning message and continue, since logger failure should not block debug session + console.log("Cannot set log level to java debuggeer.", err) + } + try { + await updateDebugSettings(); + } catch (err) { + // log a warning message and continue, since update settings failure should not block debug session + console.log("Cannot update debug settings.", err) + } +} + +function collectDebugSettings(): IDebugSettings { + const settings: IDebugSettings = {}; + if (vscode.workspace.getConfiguration().get("java.debug.settings.showHex")) { + settings.show_hex = true; + } + + if (vscode.workspace.getConfiguration().get("java.debug.settings.showStaticVariables")) { + settings.show_static_variables = true; + } + + if (vscode.workspace.getConfiguration().get("java.debug.settings.showQualifiedNames")) { + settings.show_qualified_names = true; + } + + if (vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength")) { + settings.max_string_length = vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength"); + } + + return settings; +} + function convertLogLevel(commonLogLevel: string) { // convert common log level to java log level switch (commonLogLevel.toLowerCase()) { From 8e9424bcd02765c47eb9e3ea9b68aba1639a823c Mon Sep 17 00:00:00 2001 From: andxu Date: Tue, 7 Nov 2017 18:05:54 +0800 Subject: [PATCH 2/8] change settings names --- src/configurationProvider.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index 78efead3..a7b50793 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -224,10 +224,10 @@ function configLogLevel(level) { } interface IDebugSettings { - show_hex?: boolean; - show_static_variables?: boolean; - show_qualified_names?: boolean; - max_string_length?: number; + showHex?: boolean; + showStaticVariables?: boolean; + showQualifiedNames?: boolean; + maxStringLength?: number; } async function updateDebugSettings() { @@ -256,19 +256,19 @@ async function updateUserSettings() { function collectDebugSettings(): IDebugSettings { const settings: IDebugSettings = {}; if (vscode.workspace.getConfiguration().get("java.debug.settings.showHex")) { - settings.show_hex = true; + settings.showHex = true; } if (vscode.workspace.getConfiguration().get("java.debug.settings.showStaticVariables")) { - settings.show_static_variables = true; + settings.showStaticVariables = true; } if (vscode.workspace.getConfiguration().get("java.debug.settings.showQualifiedNames")) { - settings.show_qualified_names = true; + settings.showQualifiedNames = true; } if (vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength")) { - settings.max_string_length = vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength"); + settings.maxStringLength = vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength"); } return settings; From be0067657992e9134f55a8cac139ba8818305815 Mon Sep 17 00:00:00 2001 From: andxu Date: Wed, 8 Nov 2017 11:08:09 +0800 Subject: [PATCH 3/8] merge log level to other settings. --- src/commands.ts | 2 -- src/configurationProvider.ts | 66 ++++++++---------------------------- 2 files changed, 14 insertions(+), 54 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 3e08c55e..5ddb1270 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -19,8 +19,6 @@ export const JAVA_EXECUTE_WORKSPACE_COMMAND = "java.execute.workspaceCommand"; export const JAVA_FETCH_USAGE_DATA = "vscode.java.fetchUsageData"; -export const JAVA_CONFIG_LOG_LEVEL = "vscode.java.configLogLevel"; - export const JAVA_UPDATE_DEBUG_SETTINGS = "vscode.java.updateDebugSettings"; export function executeJavaLanguageServerCommand(...rest) { diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index a7b50793..2f2210f6 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -11,7 +11,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration vscode.workspace.onDidChangeConfiguration((event) => { if (vscode.debug.activeDebugSession) { this.isUserSettingsDirty = false; - return updateUserSettings(); + return updateDebugSettings(); } else { this.isUserSettingsDirty = true; } @@ -84,7 +84,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration try { if (this.isUserSettingsDirty) { this.isUserSettingsDirty = false; - await updateUserSettings(); + await updateDebugSettings(); } // trigger build workspace @@ -219,59 +219,21 @@ function resolveMainClass() { return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS); } -function configLogLevel(level) { - return commands.executeJavaLanguageServerCommand(commands.JAVA_CONFIG_LOG_LEVEL, convertLogLevel(level)); -} - -interface IDebugSettings { - showHex?: boolean; - showStaticVariables?: boolean; - showQualifiedNames?: boolean; - maxStringLength?: number; -} - async function updateDebugSettings() { - const settings: IDebugSettings = collectDebugSettings(); - if (settings && Object.keys(settings).length) { - console.log("settings:", await commands.executeJavaLanguageServerCommand(commands.JAVA_UPDATE_DEBUG_SETTINGS, JSON.stringify(settings))); - } -} - -async function updateUserSettings() { - try { - const level = await configLogLevel(vscode.workspace.getConfiguration().get("java.debug.logLevel")); - console.log("setting log level to ", level); - } catch (err) { - // log a warning message and continue, since logger failure should not block debug session - console.log("Cannot set log level to java debuggeer.", err) - } - try { - await updateDebugSettings(); - } catch (err) { - // log a warning message and continue, since update settings failure should not block debug session - console.log("Cannot update debug settings.", err) + const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug"); + if (!debugSettingsRoot) { + return; } -} - -function collectDebugSettings(): IDebugSettings { - const settings: IDebugSettings = {}; - if (vscode.workspace.getConfiguration().get("java.debug.settings.showHex")) { - settings.showHex = true; - } - - if (vscode.workspace.getConfiguration().get("java.debug.settings.showStaticVariables")) { - settings.showStaticVariables = true; - } - - if (vscode.workspace.getConfiguration().get("java.debug.settings.showQualifiedNames")) { - settings.showQualifiedNames = true; - } - - if (vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength")) { - settings.maxStringLength = vscode.workspace.getConfiguration().get("java.debug.settings.maxStringLength"); + const logLevel = convertLogLevel(debugSettingsRoot.logLevel || ""); + if (debugSettingsRoot.settings && Object.keys(debugSettingsRoot.settings).length) { + try { + console.log("settings:", await commands.executeJavaLanguageServerCommand(commands.JAVA_UPDATE_DEBUG_SETTINGS, JSON.stringify( + { ...debugSettingsRoot.settings, logLevel }))); + } catch (err) { + // log a warning message and continue, since update settings failure should not block debug session + console.log("Cannot update debug settings.", err) + } } - - return settings; } function convertLogLevel(commonLogLevel: string) { From 23fbf51cb946b14bee79530844c516732173fb47 Mon Sep 17 00:00:00 2001 From: andxu Date: Wed, 8 Nov 2017 11:19:10 +0800 Subject: [PATCH 4/8] update desc to debug settings. --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 71665768..2a920aec 100644 --- a/package.json +++ b/package.json @@ -190,6 +190,7 @@ "java.debug.logLevel": { "type": "string", "default": "warn", + "description": "minimum level of debugger logs that are sent to VS Code", "enum": [ "error", "warn", @@ -199,18 +200,22 @@ }, "java.debug.settings.showHex": { "type": "boolean", + "description" : "whether or not the number should be displayed as hex format in variable view", "default": false }, "java.debug.settings.showStaticVariables": { "type": "boolean", + "description": "whether or not the static variables will be displayed in variable view", "default": true }, "java.debug.settings.showQualifiedNames": { "type": "boolean", + "description": "whether or not the class name should be displayed using the fully qualified class name", "default": false }, "java.debug.settings.maxStringLength": { "type": "number", + "description": "the maximum length of string displayed in variable view/console, the string longer than this length will be trimmed, defaults to 0 which means no trim is performed.", "default": 0 } } From a85108f60a483dab522b5ec491ae2b9cefcf7cbd Mon Sep 17 00:00:00 2001 From: andxu Date: Thu, 9 Nov 2017 11:08:33 +0800 Subject: [PATCH 5/8] update description for better clause --- README.md | 6 +++--- package.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 85cf0c97..5778bcf4 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,9 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht ### User Settings - `java.debug.logLevel`: minimum level of debugger logs that are sent to VS Code, defaults to `warn`. -- `java.debug.settings.showHex`: whether or not the number should be displayed as hex format in variable view, defaults to `false`. -- `java.debug.settings.showStaticVariables`: whether or not the static variables will be displayed in variable view, defaults to `true`. -- `java.debug.settings.showQualifiedNames`: whether or not the class name should be displayed using the fully qualified class name, defaults to `false`. +- `java.debug.settings.showHex`: show the number in hex format in variable view, defaults to `false`. +- `java.debug.settings.showStaticVariables`: show the static variables in variable view, defaults to `true`. +- `java.debug.settings.showQualifiedNames`: show the fully qualified class name in variable view, defaults to `false`. - `java.debug.settings.maxStringLength`: the maximum length of string displayed in variable view/console, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed. ## Feedback and Questions diff --git a/package.json b/package.json index 2a920aec..6db4b4e0 100644 --- a/package.json +++ b/package.json @@ -200,17 +200,17 @@ }, "java.debug.settings.showHex": { "type": "boolean", - "description" : "whether or not the number should be displayed as hex format in variable view", + "description" : "show the number in hex format in variable view", "default": false }, "java.debug.settings.showStaticVariables": { "type": "boolean", - "description": "whether or not the static variables will be displayed in variable view", + "description": "show the static variables in variable view", "default": true }, "java.debug.settings.showQualifiedNames": { "type": "boolean", - "description": "whether or not the class name should be displayed using the fully qualified class name", + "description": "show the fully qualified class name in variable view", "default": false }, "java.debug.settings.maxStringLength": { From 3bc362f914422e6c31e24bc01f9a3ab5b479c670 Mon Sep 17 00:00:00 2001 From: andxu Date: Thu, 9 Nov 2017 13:23:40 +0800 Subject: [PATCH 6/8] update description for better clause --- README.md | 8 ++++---- package.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5778bcf4..580d6902 100644 --- a/README.md +++ b/README.md @@ -69,10 +69,10 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht ### User Settings - `java.debug.logLevel`: minimum level of debugger logs that are sent to VS Code, defaults to `warn`. -- `java.debug.settings.showHex`: show the number in hex format in variable view, defaults to `false`. -- `java.debug.settings.showStaticVariables`: show the static variables in variable view, defaults to `true`. -- `java.debug.settings.showQualifiedNames`: show the fully qualified class name in variable view, defaults to `false`. -- `java.debug.settings.maxStringLength`: the maximum length of string displayed in variable view/console, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed. +- `java.debug.settings.showHex`: show numbers in hex format in "Variables" viewlet, defaults to `false`. +- `java.debug.settings.showStaticVariables`: show static variables in "Variables" viewlet, defaults to `true`. +- `java.debug.settings.showQualifiedNames`: show the fully qualified class name in "Variables" viewlet, defaults to `false`. +- `java.debug.settings.maxStringLength`: the maximum length of string displayed in "Variables" or "Debug Console" viewlet, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed. ## Feedback and Questions You can find the full list of issues at [Issue Tracker](https://github.com/Microsoft/vscode-java-debug/issues). You can submit a [bug or feature suggestion](https://github.com/Microsoft/vscode-java-debug/issues/new), and participate community driven [![Gitter](https://badges.gitter.im/Microsoft/vscode-java-debug.svg)](https://gitter.im/Microsoft/vscode-java-debug) diff --git a/package.json b/package.json index 6db4b4e0..f55df6e3 100644 --- a/package.json +++ b/package.json @@ -200,22 +200,22 @@ }, "java.debug.settings.showHex": { "type": "boolean", - "description" : "show the number in hex format in variable view", + "description" : "show numbers in hex format in \"Variables\" viewlet.", "default": false }, "java.debug.settings.showStaticVariables": { "type": "boolean", - "description": "show the static variables in variable view", + "description": "show static variables in \"Variables\" viewlet", "default": true }, "java.debug.settings.showQualifiedNames": { "type": "boolean", - "description": "show the fully qualified class name in variable view", + "description": "show fully qualified class names in \"Variables\" viewlet", "default": false }, "java.debug.settings.maxStringLength": { "type": "number", - "description": "the maximum length of string displayed in variable view/console, the string longer than this length will be trimmed, defaults to 0 which means no trim is performed.", + "description": "the maximum length of string displayed in \"Variables\" or \"Debug Console\" viewlet, the string longer than this length will be trimmed, defaults to 0 which means no trim is performed.", "default": 0 } } From e244a1506469716e18b561cf62ae210b6110e432 Mon Sep 17 00:00:00 2001 From: andxu Date: Thu, 9 Nov 2017 13:31:52 +0800 Subject: [PATCH 7/8] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 580d6902..60bcb6c2 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht - `java.debug.logLevel`: minimum level of debugger logs that are sent to VS Code, defaults to `warn`. - `java.debug.settings.showHex`: show numbers in hex format in "Variables" viewlet, defaults to `false`. - `java.debug.settings.showStaticVariables`: show static variables in "Variables" viewlet, defaults to `true`. -- `java.debug.settings.showQualifiedNames`: show the fully qualified class name in "Variables" viewlet, defaults to `false`. +- `java.debug.settings.showQualifiedNames`: show the fully qualified class names in "Variables" viewlet, defaults to `false`. - `java.debug.settings.maxStringLength`: the maximum length of string displayed in "Variables" or "Debug Console" viewlet, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed. ## Feedback and Questions From 81db55c55ddd74c91bb8d4f7f0176ec18d66dd70 Mon Sep 17 00:00:00 2001 From: andxu Date: Thu, 9 Nov 2017 13:53:20 +0800 Subject: [PATCH 8/8] update description for better clause --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60bcb6c2..abe12bb8 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht - `java.debug.logLevel`: minimum level of debugger logs that are sent to VS Code, defaults to `warn`. - `java.debug.settings.showHex`: show numbers in hex format in "Variables" viewlet, defaults to `false`. - `java.debug.settings.showStaticVariables`: show static variables in "Variables" viewlet, defaults to `true`. -- `java.debug.settings.showQualifiedNames`: show the fully qualified class names in "Variables" viewlet, defaults to `false`. +- `java.debug.settings.showQualifiedNames`: show fully qualified class names in "Variables" viewlet, defaults to `false`. - `java.debug.settings.maxStringLength`: the maximum length of string displayed in "Variables" or "Debug Console" viewlet, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed. ## Feedback and Questions