Skip to content

Commit

Permalink
Add way to disable run and debug code lens provider
Browse files Browse the repository at this point in the history
There are cases where it will never work properly, and it is confusing a chunk of my users that attempt to use it, and wonder why it fails

Closes microsoft#464
  • Loading branch information
ThadHouse committed Oct 31, 2018
1 parent 03830db commit 34245b5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
- `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.
- `java.debug.settings.enableHotCodeReplace`: enable hot code replace for Java code. Make sure the auto build is not disabled for [VSCode Java](https://github.com/redhat-developer/vscode-java). See the [wiki page](https://github.com/Microsoft/vscode-java-debug/wiki/Hot-Code-Replace) for more information about usages and limitations.
- `java.debug.settings.enableRunDebugCodeLens`: enable the code lens provider for the run and debug buttons over main entry points, defaults to `true`.

## Troubleshooting
Reference the [troubleshooting guide](https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md) for common errors.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@
"type": "boolean",
"description": "Enable hot code replace for Java code",
"default": true
},
"java.debug.settings.enableRunDebugCodeLens": {
"type": "boolean",
"description": "Enable the run and debug code lens providers over main methods",
"default": true
}
}
}
Expand Down
48 changes: 45 additions & 3 deletions src/debugCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,53 @@ import * as utility from "./utility";

const JAVA_RUN_COMMAND = "vscode.java.run";
const JAVA_DEBUG_COMMAND = "vscode.java.debug";
const JAVA_DEBUG_CONFIGURATION = "java.debug.settings";
const ENABLE_CODE_LENS_VARIABLE = "enableRunDebugCodeLens";

export function initializeCodeLensProvider(context: vscode.ExtensionContext): void {
context.subscriptions.push(vscode.languages.registerCodeLensProvider(JAVA_LANGID, new DebugCodeLensProvider()));
context.subscriptions.push(vscode.commands.registerCommand(JAVA_RUN_COMMAND, runJavaProgram));
context.subscriptions.push(vscode.commands.registerCommand(JAVA_DEBUG_COMMAND, debugJavaProgram));
context.subscriptions.push(new DebugCodeLensContainer());
}

class DebugCodeLensContainer implements vscode.Disposable {
private runCommand: vscode.Disposable;
private debugCommand: vscode.Disposable;
private lensProvider: vscode.Disposable | undefined;
private configurationEvent: vscode.Disposable;

constructor() {
this.runCommand = vscode.commands.registerCommand(JAVA_RUN_COMMAND, runJavaProgram);
this.debugCommand = vscode.commands.registerCommand(JAVA_DEBUG_COMMAND, debugJavaProgram);

const configuration = vscode.workspace.getConfiguration(JAVA_DEBUG_CONFIGURATION)
const isCodeLensEnabled = configuration.get<boolean>(ENABLE_CODE_LENS_VARIABLE);

if (isCodeLensEnabled) {
this.lensProvider = vscode.languages.registerCodeLensProvider(JAVA_LANGID, new DebugCodeLensProvider());
}

this.configurationEvent = vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration(JAVA_DEBUG_CONFIGURATION)) {
const newConfiguration = vscode.workspace.getConfiguration(JAVA_DEBUG_CONFIGURATION);
const newEnabled = newConfiguration.get<boolean>(ENABLE_CODE_LENS_VARIABLE);
if (newEnabled && this.lensProvider === undefined) {
this.lensProvider = vscode.languages.registerCodeLensProvider(JAVA_LANGID, new DebugCodeLensProvider());
} else if (!newEnabled && this.lensProvider !== undefined) {
this.lensProvider.dispose();
this.lensProvider = undefined;
}
}
}, this);
}

public dispose() {
if (this.lensProvider !== undefined) {
this.lensProvider.dispose();
}
this.runCommand.dispose();
this.debugCommand.dispose();
this.configurationEvent.dispose();
}

}

class DebugCodeLensProvider implements vscode.CodeLensProvider {
Expand Down

0 comments on commit 34245b5

Please sign in to comment.