1 import { compare } from "semver";
2 import { detectInstalledSDKs } from "../utils/picoSDKUtil.mjs";
3 import { Command } from "./command.mjs";
4 import { window, workspace } from "vscode";
5 import type Settings from "../settings.mjs";
6 import { SettingsKey } from "../settings.mjs";
7 import type UI from "../ui.mjs";
8 import { updateVSCodeStaticConfigs } from "../utils/vscodeConfigUtil.mjs";
9 import { join } from "path";
10 import { setPicoSDKPath, setToolchainPath } from "../utils/picoSDKEnvUtil.mjs";
12 export default class SwitchSDKCommand extends Command {
13 private _settings: Settings;
16 constructor(settings: Settings, ui: UI) {
19 this._settings = settings;
23 async execute(): Promise<void> {
24 const availableSDKs = detectInstalledSDKs()
26 compare(a.version.replace("v", ""), b.version.replace("v", ""))
29 label: `Pico SDK v${sdk.version}`,
31 // TODO: maybe remove description
32 description: `${sdk.sdkPath}; ${sdk.toolchainPath}`,
34 toolchainPath: sdk.toolchainPath,
37 const selectedSDK = await window.showQuickPick(availableSDKs, {
38 placeHolder: "Select Pico SDK",
40 ignoreFocusOut: false,
41 title: "Switch Pico SDK",
48 if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
49 await updateVSCodeStaticConfigs(
50 join(workspace.workspaceFolders?.[0].uri.fsPath, ".vscode"),
51 selectedSDK.toolchainPath
55 setPicoSDKPath(selectedSDK.sdkPath, this._settings.getExtensionId());
56 setToolchainPath(selectedSDK.toolchainPath);
57 void window.showWarningMessage(
58 "Reload window to apply changes to linting."
60 // save selected SDK version to settings
61 await this._settings.update(SettingsKey.picoSDK, selectedSDK.label);
62 this._ui.updateSDKVersion(selectedSDK.version);