8000 Get debug settings from user preference and send it to debuggee by andxu · Pull Request #135 · microsoft/vscode-java-debug · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +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 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 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
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)
Expand Down
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,33 @@
"java.debug.logLevel": {
"type": "string",
"default": "warn",
"description": "minimum level of debugger logs that are sent to VS Code",
"enum": [
"error",
"warn",
"info",
"verbose"
]
},
"java.debug.settings.showHex": {
"type": "boolean",
"description" : "show numbers in hex format in \"Variables\" viewlet.",
"default": false
},
"java.debug.settings.showStaticVariables": {
"type": "boolean",
"description": "show static variables in \"Variables\" viewlet",
"default": true
},
"java.debug.settings.showQualifiedNames": {
"type": "boolean",
"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 \"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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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) {
// TODO: need to handle error and trace telemetry
Expand Down
35 changes: 27 additions & 8 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 updateDebugSettings();
} else {
this.isUserSettingsDirty = true;
}
});
}

// Returns an initial debug configurations based on contextual information.
Expand Down Expand Up @@ -73,12 +82,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 updateDebugSettings();
}

// trigger build workspace
Expand Down Expand Up @@ -213,8 +219,21 @@ function resolveMainClass() {
return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS);
}

function configLogLevel(level) {
return commands.executeJavaLanguageServerCommand(commands.JAVA_CONFIG_LOG_LEVEL, convertLogLevel(level));
async function updateDebugSettings() {
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug");
if (!debugSettingsRoot) {
return;
}
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)
}
}
}

function convertLogLevel(commonLogLevel: string) {
Expand Down
0