Skip to content

Commit

Permalink
Fix #19 - throw error when debugging if compilation fails
Browse files Browse the repository at this point in the history
Signed-off-by: William Vinnicombe <[email protected]>
  • Loading branch information
will-v-pi committed May 22, 2024
1 parent b5d796e commit 7b77d9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/commands/compileProject.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { commands, tasks, window } from "vscode";
import { EventEmitter } from 'events';
import { Command } from "./command.mjs";
import { CommandWithResult } from "./command.mjs";
import Logger from "../logger.mjs";
import Settings, { SettingsKey } from "../settings.mjs";

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

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

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

return;
return true;
}

if (task) {
Expand Down Expand Up @@ -67,12 +67,15 @@ export default class CompileProjectCommand extends Command {
this._logger.debug(
"Task 'Compile Project' completed with code " + code.toString()
);

return code === 0;
} else {
// Task not found
this._logger.error("Task 'Compile Project' not found.");
void window.showErrorMessage("Task 'Compile Project' not found.");

return false;
}

return;
}
}
10 changes: 9 additions & 1 deletion src/commands/launchTargetPath.mts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
}

// Compile before returning
await commands.executeCommand("raspberry-pi-pico.compileProject");
const compiled = await commands.executeCommand(
"raspberry-pi-pico.compileProject"
);

if (!compiled) {
throw new Error(
"Failed to compile project - check output from the Compile Project task"
);
}

return join(fsPathFolder, "build", projectName + ".elf").replaceAll(
"\\",
Expand Down
5 changes: 4 additions & 1 deletion src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export async function activate(context: ExtensionContext): Promise<void> {
const ui = new UI(picoProjectActivityBarProvider);
ui.init();

const COMMANDS: Array<Command | CommandWithResult<string> | CommandWithArgs> =
const COMMANDS: Array<
Command | CommandWithResult<string> |
CommandWithResult<boolean> | CommandWithArgs
> =
[
new NewProjectCommand(context.extensionUri),
new SwitchSDKCommand(ui, context.extensionUri),
Expand Down

0 comments on commit 7b77d9f

Please sign in to comment.