Skip to content
Merged
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
49 changes: 39 additions & 10 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@
// Licensed under the MIT license.
import * as path from "path";
import * as vscode from "vscode";
import { sendError, setErrorCode, setUserError } from "vscode-extension-telemetry-wrapper";
import { instrumentOperation, sendInfo, sendOperationError, setErrorCode } from "vscode-extension-telemetry-wrapper";

import * as anchor from "./anchor";
import * as commands from "./commands";
import * as lsPlugin from "./languageServerPlugin";
import * as utility from "./utility";

export async function buildWorkspace(): Promise<boolean> {
try {
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false);
} catch (err) {
return handleBuildFailure(err);
const buildResult = await instrumentOperation("build", async (operationId: string) => {
let error;
try {
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false);
} catch (err) {
error = err;
}

return {
error,
operationId,
};
})();

if (buildResult.error) {
return handleBuildFailure(buildResult.operationId, buildResult.error);
}

return true;
}

async function handleBuildFailure(err: any): Promise<boolean> {
async function handleBuildFailure(operationId: string, err: any): Promise<boolean> {
if (err instanceof utility.JavaExtensionNotActivatedError) {
utility.guideToInstallJavaExtension();
return false;
Expand All @@ -29,19 +41,22 @@ async function handleBuildFailure(err: any): Promise<boolean> {
message: "Build failed",
});
setErrorCode(error, Number(err));
sendError(error);

sendOperationError(operationId, "build", error);
if (err === lsPlugin.CompileWorkspaceStatus.WITHERROR || err === lsPlugin.CompileWorkspaceStatus.FAILED) {
if (checkErrorsReportedByJavaExtension()) {
vscode.commands.executeCommand("workbench.actions.view.problems");
}

const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?",
"Proceed", "Fix...", "Cancel");
sendInfo(operationId, {
operationName: "build",
choiceForBuildError: ans || "esc",
});
if (ans === "Proceed") {
return true;
} else if (ans === "Fix...") {
showFixSuggestions();
showFixSuggestions(operationId);
}

return false;
Expand All @@ -64,7 +79,7 @@ function checkErrorsReportedByJavaExtension(): boolean {
return false;
}

async function showFixSuggestions() {
async function showFixSuggestions(operationId: string) {
let buildFiles = [];
try {
buildFiles = await lsPlugin.resolveBuildFiles();
Expand All @@ -83,6 +98,10 @@ async function showFixSuggestions() {
detail: "Force the language server to update the project configuration/classpath",
});
}
pickitems.push({
label: "Open log file",
detail: "Open log file to view more details for the build errors",
});
pickitems.push({
label: "Troubleshooting guide",
detail: "Find more detail about the troubleshooting steps",
Expand All @@ -91,12 +110,22 @@ async function showFixSuggestions() {
const ans = await vscode.window.showQuickPick(pickitems, {
placeHolder: "Please fix the errors in PROBLEMS first, then try the fix suggestions below.",
});
sendInfo(operationId, {
operationName: "build",
choiceForBuildFix: ans ? ans.label : "esc",
});
if (!ans) {
return;
}

if (ans.label === "Clean workspace cache") {
vscode.commands.executeCommand("java.clean.workspace");
} else if (ans.label === "Update project configuration") {
for (const buildFile of buildFiles) {
await vscode.commands.executeCommand("java.projectConfiguration.update", vscode.Uri.parse(buildFile));
}
} else if (ans.label === "Open log file") {
vscode.commands.executeCommand("java.open.serverLog");
} else if (ans.label === "Troubleshooting guide") {
utility.openTroubleshootingPage("Build failed", anchor.BUILD_FAILED);
}
Expand Down