]> Git Repo - pico-vscode.git/blob - src/commands/compileProject.mts
Fix #36, Downgrading SDK >= 2.0.0 with unsupported PICO_BOARD breaks cmake
[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 && settings.getBoolean(SettingsKey.useCmakeTools)
25     ) {
26       // Compile with CMake Tools
27       await commands.executeCommand(
28         "cmake.launchTargetPath"
29       );
30
31       return true;
32     }
33
34     if (task) {
35       // Execute the task
36       const emitter = new EventEmitter();
37
38       // add callbacks for task completion
39       const end = tasks.onDidEndTaskProcess(e => {
40         if (e.execution.task === task) {
41           emitter.emit(
42             "terminated",
43             e.exitCode === undefined ? -1 : e.exitCode
44           );
45         }
46       });
47       const end2 = tasks.onDidEndTask(e => {
48         if (e.execution.task === task) {
49           emitter.emit("terminated", -1);
50         }
51       });
52
53       await tasks.executeTask(task);
54       // eslint-disable-next-line @typescript-eslint/no-unused-vars
55       const code = await new Promise<number>((resolve, reject) => {
56         emitter.on("terminated", code => {
57           if (typeof(code) === 'number') {
58             resolve(code);
59           } else {
60             resolve(-1);
61           }
62         });
63       });
64
65       // dispose of callbacks
66       end.dispose();
67       end2.dispose();
68       this._logger.debug(
69         "Task 'Compile Project' completed with code " + code.toString()
70       );
71
72       return code === 0;
73     } else {
74       // Task not found
75       this._logger.error("Task 'Compile Project' not found.");
76       void window.showErrorMessage("Task 'Compile Project' not found.");
77
78       return false;
79     }
80
81   }
82 }
This page took 0.030242 seconds and 4 git commands to generate.