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
15 changes: 11 additions & 4 deletions Extension/src/LanguageServer/cppBuildTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
let error: string = "";
let stdout: string = "";
let stderr: string = "";
const result: number = await new Promise<number>(resolve => {
const spawnResult: number = await new Promise<number>(resolve => {
if (child) {
child.on('error', err => {
splitWriteEmitter(err.message);
Expand All @@ -427,29 +427,36 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
if (result === null) {
this.writeEmitter.fire(localize("build.run.terminated", "Build run was terminated.") + this.endOfLine);
resolve(-1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the real problem that resolve(-1) doesn't exit the function and we immediately send resolve(0) right after this? What happens if you just add a return; after line 444? Maybe the reason this change works is because it now ignores the -1 and 0 returned in the failed build case.

(It's possible you might also need to do something to deal with multiple resolves being called if both the error block and the close block can execute.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In new changes, I kept the result of the promise and checked for when it is -1.

} else {
resolve(0);
}
resolve(0);
});
}
});
this.printBuildSummary(error, stdout, stderr);
let result: number = this.printBuildSummary(error, stdout, stderr);
if (spawnResult === -1) {
result = -1;
}
this.closeEmitter.fire(result);
} catch {
this.closeEmitter.fire(-1);
}
}

private printBuildSummary(error: string, stdout: string, stderr: string): void {
private printBuildSummary(error: string, stdout: string, stderr: string): number {
if (error || (!stdout && stderr && stderr.includes("error")) ||
(stdout && stdout.includes("error C"))) { // cl.exe compiler errors
telemetry.logLanguageServerEvent("cppBuildTaskError");
this.writeEmitter.fire(localize("build.finished.with.error", "Build finished with error(s).") + this.endOfLine);
return -1;
} else if ((!stdout && stderr) || // gcc/clang
(stdout && stdout.includes("warning C"))) { // cl.exe compiler warnings
telemetry.logLanguageServerEvent("cppBuildTaskWarnings");
this.writeEmitter.fire(localize("build.finished.with.warnings", "Build finished with warning(s).") + this.endOfLine);
return 0;
} else {
this.writeEmitter.fire(localize("build.finished.successfully", "Build finished successfully.") + this.endOfLine);
return 0;
}
}
}