diff --git a/src/commands/compileProject.mts b/src/commands/compileProject.mts index 0ef49a85..e7034555 100644 --- a/src/commands/compileProject.mts +++ b/src/commands/compileProject.mts @@ -1,4 +1,5 @@ import { commands, tasks, window } from "vscode"; +import { EventEmitter } from 'events'; import { Command } from "./command.mjs"; import Logger from "../logger.mjs"; import Settings, { SettingsKey } from "../settings.mjs"; @@ -34,7 +35,25 @@ export default class CompileProjectCommand extends Command { if (task) { // Execute the task + var emitter = new EventEmitter(); + + // add callbacks for task completion + var end = tasks.onDidEndTaskProcess(e => { + emitter.emit("terminated", e.exitCode); + }); + var end2 = tasks.onDidEndTask(e => { + emitter.emit("terminated", -1); + }); + await tasks.executeTask(task); + var code = await new Promise((resolve, reject) => { + emitter.on("terminated", code => resolve(code)); + }); + + // dispose of callbacks + end.dispose(); + end2.dispose(); + this._logger.debug("Task 'Compile Project' completed with code " + code); } else { // Task not found this._logger.error("Task 'Compile Project' not found.");