]> Git Repo - pico-vscode.git/blob - src/commands/compileProject.mts
Test system gdb for arm_any support
[pico-vscode.git] / src / commands / compileProject.mts
1 import { commands, tasks, window } from "vscode";
2 import { EventEmitter } from "events";
3 import { CommandWithResult } from "./command.mjs";
4 import Logger from "../logger.mjs";
5 import Settings, { SettingsKey } from "../settings.mjs";
6
7 export default class CompileProjectCommand extends CommandWithResult<boolean> {
8   private _logger: Logger = new Logger("CompileProjectCommand");
9
10   public static readonly id = "compileProject";
11
12   constructor() {
13     super(CompileProjectCommand.id);
14   }
15
16   async execute(): Promise<boolean> {
17     // Get the task with the specified name
18     const task = (await tasks.fetchTasks()).find(
19       task => task.name === "Compile Project"
20     );
21
22     const settings = Settings.getInstance();
23     if (
24       settings !== undefined &&
25       settings.getBoolean(SettingsKey.useCmakeTools)
26     ) {
27       // Compile with CMake Tools
28       await commands.executeCommand("cmake.launchTargetPath");
29
30       return true;
31     }
32
33     if (task) {
34       // Execute the task
35       const emitter = new EventEmitter();
36
37       // add callbacks for task completion
38       const end = tasks.onDidEndTaskProcess(e => {
39         if (e.execution.task === task) {
40           emitter.emit(
41             "terminated",
42             e.exitCode === undefined ? -1 : e.exitCode
43           );
44         }
45       });
46       const end2 = tasks.onDidEndTask(e => {
47         if (e.execution.task === task) {
48           emitter.emit("terminated", -1);
49         }
50       });
51
52       await tasks.executeTask(task);
53       // eslint-disable-next-line @typescript-eslint/no-unused-vars
54       const code = await new Promise<number>((resolve, reject) => {
55         emitter.on("terminated", code => {
56           if (typeof code === "number") {
57             resolve(code);
58           } else {
59             resolve(-1);
60           }
61         });
62       });
63
64       // dispose of callbacks
65       end.dispose();
66       end2.dispose();
67       this._logger.debug(
68         "Task 'Compile Project' completed with code " + code.toString()
69       );
70
71       return code === 0;
72     } else {
73       // Task not found
74       this._logger.error("Task 'Compile Project' not found.");
75       void window.showErrorMessage("Task 'Compile Project' not found.");
76
77       return false;
78     }
79   }
80 }
This page took 0.03422 seconds and 4 git commands to generate.