Skip to content

Commit dfd56fe

Browse files
committed
Force users to select the Pico kit when using the CMake Tools Extension Integration
This pops us the kit selection dialog, and a notification saying to select the Pico kit, and then throws an error and prompts the user to try again if they selected the wrong kit. I think this is the closest we can get to actually specifying the kit in the CMake Tools extension
1 parent 05de4cf commit dfd56fe

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

scripts/pico_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ def generateProjectFiles(
11261126

11271127
# settings
11281128
settings = f'''{{
1129+
"cmake.showSystemKits": false,
11291130
"cmake.options.statusBarVisibility": "hidden",
11301131
"cmake.options.advanced": {{
11311132
"build": {{

src/commands/compileProject.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { EventEmitter } from "events";
33
import { CommandWithResult } from "./command.mjs";
44
import Logger from "../logger.mjs";
55
import Settings, { SettingsKey } from "../settings.mjs";
6-
6+
import { cmakeToolsForcePicoKit } from "../utils/cmakeToolsUtil.mjs";
77
export default class CompileProjectCommand extends CommandWithResult<boolean> {
88
private _logger: Logger = new Logger("CompileProjectCommand");
99

@@ -24,6 +24,9 @@ export default class CompileProjectCommand extends CommandWithResult<boolean> {
2424
settings !== undefined &&
2525
settings.getBoolean(SettingsKey.useCmakeTools)
2626
) {
27+
// Ensure the Pico kit is selected
28+
await cmakeToolsForcePicoKit();
29+
2730
// Compile with CMake Tools
2831
await commands.executeCommand("cmake.launchTargetPath");
2932

src/commands/launchTargetPath.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CommandWithResult } from "./command.mjs";
33
import { commands, window, workspace } from "vscode";
44
import { join } from "path";
55
import Settings, { SettingsKey } from "../settings.mjs";
6+
import { cmakeToolsForcePicoKit } from "../utils/cmakeToolsUtil.mjs";
67

78
export default class LaunchTargetPathCommand extends CommandWithResult<string> {
89
constructor() {
@@ -66,6 +67,9 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
6667
settings !== undefined &&
6768
settings.getBoolean(SettingsKey.useCmakeTools)
6869
) {
70+
// Ensure the Pico kit is selected
71+
await cmakeToolsForcePicoKit();
72+
6973
// Compile with CMake Tools
7074
const path: string = await commands.executeCommand(
7175
"cmake.launchTargetPath"

src/extension.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import FlashProjectSWDCommand from "./commands/flashProjectSwd.mjs";
8282
import { NewMicroPythonProjectPanel } from "./webview/newMicroPythonProjectPanel.mjs";
8383
import type { Progress as GotProgress } from "got";
8484
import findPython, { showPythonNotFoundError } from "./utils/pythonHelper.mjs";
85-
85+
import { cmakeToolsForcePicoKit } from "./utils/cmakeToolsUtil.mjs";
8686
export async function activate(context: ExtensionContext): Promise<void> {
8787
Logger.info(LoggerSource.extension, "Extension activation triggered");
8888

@@ -811,6 +811,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
811811
);
812812
}
813813
});
814+
} else if (settings.getBoolean(SettingsKey.useCmakeTools)) {
815+
// Ensure the Pico kit is selected
816+
await cmakeToolsForcePicoKit();
814817
} else {
815818
Logger.info(
816819
LoggerSource.extension,

src/utils/cmakeToolsUtil.mts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { commands, window, ProgressLocation } from "vscode";
2+
3+
4+
export async function cmakeToolsForcePicoKit(): Promise<void> {
5+
let cmakeToolsKit = await commands.executeCommand(
6+
"cmake.buildKit"
7+
);
8+
if (cmakeToolsKit === "Pico") {
9+
return;
10+
}
11+
12+
await window.withProgress({
13+
location: ProgressLocation.Notification,
14+
title: "Select the Pico kit in the dialog at the top of the window",
15+
cancellable: false,
16+
}, async progress => {
17+
let i = 0;
18+
while (cmakeToolsKit !== "Pico") {
19+
if (i >= 2) {
20+
const result = await window.showErrorMessage(
21+
"You did not select the Pico kit - " +
22+
"you must select the Pico kit in the dialog, " +
23+
"else this extension will not work",
24+
"Try again",
25+
"Cancel"
26+
);
27+
28+
if (result === "Try again") {
29+
i = 0;
30+
continue;
31+
}
32+
33+
progress.report({increment: 100});
34+
35+
return;
36+
}
37+
await commands.executeCommand("cmake.selectKit");
38+
cmakeToolsKit = await commands.executeCommand(
39+
"cmake.buildKit"
40+
);
41+
i++;
42+
}
43+
progress.report({increment: 100});
44+
45+
return;
46+
});
47+
}

0 commit comments

Comments
 (0)