Skip to content

Commit 5ab4fd8

Browse files
Add an user setting to control whether to build the workspace before debugging (#485)
* Add an user setting to control whether to build the workspace before debuging Signed-off-by: Jinbo Wang <jinbwan@microsoft.com> * Add Chinese translation for the new setting Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
1 parent a458e5e commit 5ab4fd8

5 files changed

Lines changed: 27 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
9191
- `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.
9292
- `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.
9393
- `java.debug.settings.enableRunDebugCodeLens`: enable the code lens provider for the run and debug buttons over main entry points, defaults to `true`.
94+
- `java.debug.settings.forceBuildBeforeLaunch`: force building the workspace before launching java program, defaults to `true`.
9495

9596
## Troubleshooting
9697
Reference the [troubleshooting guide](https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md) for common errors.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@
394394
"type": "boolean",
395395
"description": "%java.debugger.configuration.enableRunDebugCodeLens.description%",
396396
"default": true
397+
},
398+
"java.debug.settings.forceBuildBeforeLaunch": {
399+
"type": "boolean",
400+
"description": "%java.debugger.configuration.forceBuildBeforeLaunch%",
401+
"default": true
397402
}
398403
}
399404
}

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@
3636
"java.debugger.configuration.showQualifiedNames.description": "Show fully qualified class names in \"Variables\" viewlet.",
3737
"java.debugger.configuration.maxStringLength.description": "The maximum length of strings displayed in \"Variables\" or \"Debug Console\" viewlet, strings longer than this length will be trimmed, if 0 no trim is performed.",
3838
"java.debugger.configuration.enableHotCodeReplace.description": "Enable hot code replace for Java code.",
39-
"java.debugger.configuration.enableRunDebugCodeLens.description": "Enable the run and debug code lens providers over main methods."
39+
"java.debugger.configuration.enableRunDebugCodeLens.description": "Enable the run and debug code lens providers over main methods.",
40+
"java.debugger.configuration.forceBuildBeforeLaunch": "Force building the workspace before launching java program."
4041
}

package.nls.zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@
3636
"java.debugger.configuration.showQualifiedNames.description": "在“变量”视图中显示类的全名。",
3737
"java.debugger.configuration.maxStringLength.description": "设定“变量”或“调试控制台”视图中显示的字符串最大长度,长度超过部分将被剪掉。如果值为0,则不执行修剪。",
3838
"java.debugger.configuration.enableHotCodeReplace.description": "为Java代码启用热代码替换。",
39-
"java.debugger.configuration.enableRunDebugCodeLens.description": "在main方法上启用CodeLens标记。"
39+
"java.debugger.configuration.enableRunDebugCodeLens.description": "在main方法上启用CodeLens标记。",
40+
"java.debugger.configuration.forceBuildBeforeLaunch": "在启动java程序之前强制编译整个工作空间。"
4041
}

src/configurationProvider.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,18 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
147147
}
148148

149149
if (config.request === "launch") {
150-
try {
151-
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
152-
} catch (err) {
153-
const ans = await utility.showErrorMessageWithTroubleshooting({
154-
message: "Build failed, do you want to continue?",
155-
type: Type.USAGEERROR,
156-
anchor: anchor.BUILD_FAILED,
157-
}, "Proceed", "Abort");
158-
if (ans !== "Proceed") {
159-
return undefined;
150+
if (needsBuildWorkspace()) {
151+
try {
152+
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
153+
} catch (err) {
154+
const ans = await utility.showErrorMessageWithTroubleshooting({
155+
message: "Build failed, do you want to continue?",
156+
type: Type.USAGEERROR,
157+
anchor: anchor.BUILD_FAILED,
158+
}, "Proceed", "Abort");
159+
if (ans !== "Proceed") {
160+
return undefined;
161+
}
160162
}
161163
}
162164

@@ -475,6 +477,11 @@ async function updateDebugSettings() {
475477
}
476478
}
477479

480+
function needsBuildWorkspace(): boolean {
481+
const debugSettingsRoot: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
482+
return debugSettingsRoot ? debugSettingsRoot.forceBuildBeforeLaunch : true;
483+
}
484+
478485
function convertLogLevel(commonLogLevel: string) {
479486
// convert common log level to java log level
480487
switch (commonLogLevel.toLowerCase()) {

0 commit comments

Comments
 (0)