Skip to content

Commit 42fccc0

Browse files
Only pop-up build errors notification when the errors are on the running project's classpath (#1263)
1 parent 024d2da commit 42fccc0

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

src/build.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as utility from "./utility";
1111

1212
const JAVA_DEBUG_CONFIGURATION = "java.debug.settings";
1313
const ON_BUILD_FAILURE_PROCEED = "onBuildFailureProceed";
14+
const CANCELLED_CODE = -32800;
1415

1516
enum CompileWorkspaceStatus {
1617
FAILED = 0,
@@ -19,25 +20,44 @@ enum CompileWorkspaceStatus {
1920
CANCELLED = 3,
2021
}
2122

22-
export async function buildWorkspace(progressReporter: IProgressReporter): Promise<boolean> {
23+
export interface BuildParams {
24+
readonly mainClass: string;
25+
readonly projectName?: string;
26+
readonly filePath?: string;
27+
readonly isFullBuild: boolean;
28+
}
29+
30+
export async function buildWorkspace(params: BuildParams, progressReporter: IProgressReporter): Promise<boolean> {
31+
const startAt = new Date().getTime();
2332
const buildResult = await instrumentOperation("build", async (operationId: string) => {
24-
let error;
33+
let status;
2534
try {
26-
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false, progressReporter.getCancellationToken());
35+
status = await commands.executeJavaLanguageServerCommand(commands.JAVA_BUILD_WORKSPACE,
36+
JSON.stringify(params),
37+
progressReporter.getCancellationToken());
2738
} catch (err) {
28-
error = err;
39+
status = (err && err.code === CANCELLED_CODE) ? CompileWorkspaceStatus.CANCELLED : err;
2940
}
3041

3142
return {
32-
error,
43+
status,
3344
operationId,
3445
};
3546
})();
3647

37-
if (progressReporter.isCancelled() || buildResult.error === CompileWorkspaceStatus.CANCELLED) {
48+
if (progressReporter.isCancelled() || buildResult.status === CompileWorkspaceStatus.CANCELLED) {
3849
return false;
50+
} else if (buildResult.status === CompileWorkspaceStatus.SUCCEED) {
51+
return true;
3952
} else {
40-
return handleBuildFailure(buildResult.operationId, buildResult.error, progressReporter);
53+
const elapsed = new Date().getTime() - startAt;
54+
const humanVisibleDelay = elapsed < 150 ? 150 : 0;
55+
await new Promise(resolve => {
56+
setTimeout(() => { // set a timeout so user still can see a compiling message.
57+
resolve(null);
58+
}, humanVisibleDelay);
59+
});
60+
return handleBuildFailure(buildResult.operationId, buildResult.status, progressReporter);
4161
}
4262
}
4363

@@ -62,12 +82,16 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
6282
}
6383

6484
progressReporter.hide(true);
65-
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Proceed", "Fix...", "Cancel");
85+
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Continue", "Always Continue", "Fix...");
6686
sendInfo(operationId, {
6787
operationName: "build",
6888
choiceForBuildError: ans || "esc",
6989
});
70-
if (ans === "Proceed") {
90+
if (ans === "Continue") {
91+
return true;
92+
} else if (ans === "Always Continue") {
93+
const debugSettings: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.debug.settings");
94+
debugSettings?.update("onBuildFailureProceed", true);
7195
return true;
7296
} else if (ans === "Fix...") {
7397
showFixSuggestions(operationId);

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const JAVA_RESOLVE_MAINCLASS = "vscode.java.resolveMainClass";
1616

1717
export const JAVA_VALIDATE_LAUNCHCONFIG = "vscode.java.validateLaunchConfig";
1818

19-
export const JAVA_BUILD_WORKSPACE = "java.workspace.compile";
19+
export const JAVA_BUILD_WORKSPACE = "vscode.java.buildWorkspace";
2020

2121
export const JAVA_EXECUTE_WORKSPACE_COMMAND = "java.execute.workspaceCommand";
2222

src/configurationProvider.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,28 +248,30 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
248248
config.internalConsoleOptions = "neverOpen";
249249
}
250250

251-
if (needsBuildWorkspace()) {
252-
progressReporter.report("Compiling...");
253-
const proceed = await buildWorkspace(progressReporter);
254-
if (!proceed) {
255-
return undefined;
256-
}
257-
}
258251

259252
if (progressReporter.isCancelled()) {
260253
return undefined;
261254
}
262-
if (!config.mainClass) {
263-
progressReporter.report("Resolving main class...");
264-
} else {
265-
progressReporter.report("Resolving launch configuration...");
266-
}
255+
256+
progressReporter.report("Resolving main class...");
267257
const mainClassOption = await this.resolveAndValidateMainClass(folder && folder.uri, config, progressReporter);
268258
if (!mainClassOption || !mainClassOption.mainClass) { // Exit silently if the user cancels the prompt fix by ESC.
269259
// Exit the debug session.
270260
return undefined;
271261
}
272262

263+
if (needsBuildWorkspace()) {
264+
progressReporter.report("Compiling...");
265+
const proceed = await buildWorkspace({
266+
mainClass: mainClassOption.mainClass,
267+
projectName: mainClassOption.projectName,
268+
isFullBuild: false,
269+
}, progressReporter);
270+
if (!proceed) {
271+
return undefined;
272+
}
273+
}
274+
273275
progressReporter.report("Resolving launch configuration...");
274276
config.mainClass = mainClassOption.mainClass;
275277
config.projectName = mainClassOption.projectName;

0 commit comments

Comments
 (0)