Skip to content

Commit 7b77d9f

Browse files
committed
Fix #19 - throw error when debugging if compilation fails
Signed-off-by: William Vinnicombe <[email protected]>
1 parent b5d796e commit 7b77d9f

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/commands/compileProject.mts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { commands, tasks, window } from "vscode";
22
import { EventEmitter } from 'events';
3-
import { Command } from "./command.mjs";
3+
import { CommandWithResult } from "./command.mjs";
44
import Logger from "../logger.mjs";
55
import Settings, { SettingsKey } from "../settings.mjs";
66

7-
export default class CompileProjectCommand extends Command {
7+
export default class CompileProjectCommand extends CommandWithResult<boolean> {
88
private _logger: Logger = new Logger("CompileProjectCommand");
99

1010
public static readonly id = "compileProject";
@@ -13,7 +13,7 @@ export default class CompileProjectCommand extends Command {
1313
super(CompileProjectCommand.id);
1414
}
1515

16-
async execute(): Promise<void> {
16+
async execute(): Promise<boolean> {
1717
// Get the task with the specified name
1818
const task = (await tasks.fetchTasks()).find(task => () => {
1919
console.log(`[TASK] ${task.name}`);
@@ -30,7 +30,7 @@ export default class CompileProjectCommand extends Command {
3030
"cmake.launchTargetPath"
3131
);
3232

33-
return;
33+
return true;
3434
}
3535

3636
if (task) {
@@ -67,12 +67,15 @@ export default class CompileProjectCommand extends Command {
6767
this._logger.debug(
6868
"Task 'Compile Project' completed with code " + code.toString()
6969
);
70+
71+
return code === 0;
7072
} else {
7173
// Task not found
7274
this._logger.error("Task 'Compile Project' not found.");
7375
void window.showErrorMessage("Task 'Compile Project' not found.");
76+
77+
return false;
7478
}
7579

76-
return;
7780
}
7881
}

src/commands/launchTargetPath.mts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
8585
}
8686

8787
// Compile before returning
88-
await commands.executeCommand("raspberry-pi-pico.compileProject");
88+
const compiled = await commands.executeCommand(
89+
"raspberry-pi-pico.compileProject"
90+
);
91+
92+
if (!compiled) {
93+
throw new Error(
94+
"Failed to compile project - check output from the Compile Project task"
95+
);
96+
}
8997

9098
return join(fsPathFolder, "build", projectName + ".elf").replaceAll(
9199
"\\",

src/extension.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ export async function activate(context: ExtensionContext): Promise<void> {
7979
const ui = new UI(picoProjectActivityBarProvider);
8080
ui.init();
8181

82-
const COMMANDS: Array<Command | CommandWithResult<string> | CommandWithArgs> =
82+
const COMMANDS: Array<
83+
Command | CommandWithResult<string> |
84+
CommandWithResult<boolean> | CommandWithArgs
85+
> =
8386
[
8487
new NewProjectCommand(context.extensionUri),
8588
new SwitchSDKCommand(ui, context.extensionUri),

0 commit comments

Comments
 (0)