Skip to content

Commit b9096ce

Browse files
Use a progress reporter to hint the current build status when run or debug a program (#919)
* Use a progress reporter to hint the current build status when run or debug a program * Align build and configuration error messages with progress reporter * refactor the progress api based on feedback * Hide progress reporter only when necessary * Refactor the progressReporter api interfaces per comments * Simplify report method * Refine the progress message * Add overload api for createProgressReporter
1 parent b41dabe commit b9096ce

15 files changed

+636
-194
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
121121
- `java.debug.settings.jdwp.limitOfVariablesPerJdwpRequest`: The maximum number of variables or fields that can be requested in one JDWP request. The higher the value, the less frequently debuggee will be requested when expanding the variable view. Also a large number can cause JDWP request timeout. Defaults to 100.
122122
- `java.debug.settings.jdwp.requestTimeout`: The timeout (ms) of JDWP request when the debugger communicates with the target JVM. Defaults to 3000.
123123
- `java.debug.settings.vmArgs`: The default VM arguments to launch the Java program. Eg. Use '-Xmx1G -ea' to increase the heap size to 1GB and enable assertions. If you want to customize the VM arguments for a specific debug session, please modify the 'vmArgs' config in launch.json.
124+
- `java.silentNotification`: Controls whether notifications can be used to report progress. If true, use status bar to report progress instead. Defaults to `false`.
124125

125126
Pro Tip: The documentation [Configuration.md](https://github.com/microsoft/vscode-java-debug/blob/master/Configuration.md) provides lots of samples to demonstrate how to use these debug configurations, recommend to take a look.
126127

package-lock.json

Lines changed: 27 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,11 @@
741741
"type": "string",
742742
"description": "%java.debugger.configuration.vmArgs.description%",
743743
"default": ""
744+
},
745+
"java.silentNotification": {
746+
"type": "boolean",
747+
"description": "%java.debugger.configuration.silentNotification%",
748+
"default": false
744749
}
745750
}
746751
}
@@ -756,7 +761,8 @@
756761
"@types/glob": "^7.1.3",
757762
"@types/lodash": "^4.14.137",
758763
"@types/mocha": "^5.2.7",
759-
"@types/node": "^8.10.51",
764+
"@types/node": "^14.14.10",
765+
"@types/uuid": "^8.3.0",
760766
"@types/vscode": "1.49.0",
761767
"cross-env": "^5.2.0",
762768
"gulp": "^4.0.2",
@@ -765,13 +771,15 @@
765771
"shelljs": "^0.8.3",
766772
"ts-loader": "^5.4.5",
767773
"tslint": "^5.18.0",
768-
"typescript": "^3.5.3",
774+
"typescript": "^4.1.2",
769775
"vscode-test": "^1.2.0",
770776
"webpack": "^4.39.2",
771777
"webpack-cli": "^3.3.7"
772778
},
773779
"dependencies": {
780+
"compare-versions": "^3.6.0",
774781
"lodash": "^4.17.19",
782+
"uuid": "^8.3.1",
775783
"vscode-extension-telemetry": "^0.1.6",
776784
"vscode-extension-telemetry-wrapper": "^0.8.0"
777785
}

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@
5858
"java.debugger.configuration.exceptionBreakpoint.skipClasses": "Skip the specified classes when breaking on exception. You could use the built-in variables such as '$JDK' and '$Libraries' to skip a group of classes, or add a specific class name expression, e.g. java.*, *.Foo",
5959
"java.debugger.configuration.jdwp.limitOfVariablesPerJdwpRequest.description": "The maximum number of variables or fields that can be requested in one JDWP request. The higher the value, the less frequently debuggee will be requested when expanding the variable view. Also a large number can cause JDWP request timeout.",
6060
"java.debugger.configuration.jdwp.requestTimeout.description": "The timeout (ms) of JDWP request when the debugger communicates with the target JVM.",
61-
"java.debugger.configuration.vmArgs.description": "The default VM arguments to launch the Java program. Eg. Use '-Xmx1G -ea' to increase the heap size to 1GB and enable assertions. If you want to customize the VM arguments for a specific debug session, please modify the 'vmArgs' config in launch.json."
61+
"java.debugger.configuration.vmArgs.description": "The default VM arguments to launch the Java program. Eg. Use '-Xmx1G -ea' to increase the heap size to 1GB and enable assertions. If you want to customize the VM arguments for a specific debug session, please modify the 'vmArgs' config in launch.json.",
62+
"java.debugger.configuration.silentNotification": "Controls whether notifications can be used to report progress. If true, use status bar to report progress instead."
6263
}

package.nls.zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
"java.debugger.configuration.exceptionBreakpoint.skipClasses": "当发生异常时,跳过指定的类。你可以使用内置变量,如'$JDK'和'$Libraries'来跳过一组类,或者添加一个特定的类名表达式,如java.*,*.Foo。",
5757
"java.debugger.configuration.jdwp.limitOfVariablesPerJdwpRequest.description": "一次JDWP请求中可以请求的变量或字段的最大数量。该值越高,在展开变量视图时,请求debuggee的频率就越低。同时数量过大也会导致JDWP请求超时。",
5858
"java.debugger.configuration.jdwp.requestTimeout.description": "调试器与目标JVM通信时JDWP请求的超时时间(ms)。",
59-
"java.debugger.configuration.vmArgs.description": "启动Java程序的默认VM参数。例如,使用'-Xmx1G -ea'将堆大小增加到1GB并启用断言。如果要为特定的调试会话定制VM参数,请修改launch.json中的'vmArgs'配置。"
59+
"java.debugger.configuration.vmArgs.description": "启动Java程序的默认VM参数。例如,使用'-Xmx1G -ea'将堆大小增加到1GB并启用断言。如果要为特定的调试会话定制VM参数,请修改launch.json中的'vmArgs'配置。",
60+
"java.debugger.configuration.silentNotification": "控制是否可以使用通知来报告进度。如果为真,则使用状态栏来报告进度。"
6061
}

src/build.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ import { instrumentOperation, sendInfo, sendOperationError, setErrorCode } from
77
import * as anchor from "./anchor";
88
import * as commands from "./commands";
99
import * as lsPlugin from "./languageServerPlugin";
10+
import { IProgressReporter } from "./progressAPI";
1011
import * as utility from "./utility";
1112

1213
const JAVA_DEBUG_CONFIGURATION = "java.debug.settings";
1314
const ON_BUILD_FAILURE_PROCEED = "onBuildFailureProceed";
1415

15-
export async function buildWorkspace(): Promise<boolean> {
16+
enum CompileWorkspaceStatus {
17+
FAILED = 0,
18+
SUCCEED = 1,
19+
WITHERROR = 2,
20+
CANCELLED = 3,
21+
}
22+
23+
export async function buildWorkspace(progressReporter: IProgressReporter): Promise<boolean> {
1624
const buildResult = await instrumentOperation("build", async (operationId: string) => {
1725
let error;
1826
try {
19-
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false);
27+
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false, progressReporter.getCancellationToken());
2028
} catch (err) {
2129
error = err;
2230
}
@@ -27,14 +35,14 @@ export async function buildWorkspace(): Promise<boolean> {
2735
};
2836
})();
2937

30-
if (buildResult.error) {
31-
return handleBuildFailure(buildResult.operationId, buildResult.error);
38+
if (progressReporter.isCancelled() || buildResult.error === CompileWorkspaceStatus.CANCELLED) {
39+
return false;
40+
} else {
41+
return handleBuildFailure(buildResult.operationId, buildResult.error, progressReporter);
3242
}
33-
34-
return true;
3543
}
3644

37-
async function handleBuildFailure(operationId: string, err: any): Promise<boolean> {
45+
async function handleBuildFailure(operationId: string, err: any, progressReporter: IProgressReporter): Promise<boolean> {
3846
const configuration = vscode.workspace.getConfiguration(JAVA_DEBUG_CONFIGURATION);
3947
const onBuildFailureProceed = configuration.get<boolean>(ON_BUILD_FAILURE_PROCEED);
4048

@@ -48,13 +56,13 @@ async function handleBuildFailure(operationId: string, err: any): Promise<boolea
4856
});
4957
setErrorCode(error, Number(err));
5058
sendOperationError(operationId, "build", error);
51-
if (err === lsPlugin.CompileWorkspaceStatus.WITHERROR || err === lsPlugin.CompileWorkspaceStatus.FAILED) {
59+
if (!onBuildFailureProceed && (err === lsPlugin.CompileWorkspaceStatus.WITHERROR || err === lsPlugin.CompileWorkspaceStatus.FAILED)) {
5260
if (checkErrorsReportedByJavaExtension()) {
5361
vscode.commands.executeCommand("workbench.actions.view.problems");
5462
}
5563

56-
const ans = onBuildFailureProceed ? "Proceed" : (await vscode.window.showErrorMessage("Build failed, do you want to continue?",
57-
"Proceed", "Fix...", "Cancel"));
64+
progressReporter.hide(true);
65+
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Proceed", "Fix...", "Cancel");
5866
sendInfo(operationId, {
5967
operationName: "build",
6068
choiceForBuildError: ans || "esc",

0 commit comments

Comments
 (0)