]> Git Repo - pico-vscode.git/blob - src/commands/switchSDK.mts
Add `getSDKPath`, `getToolchainPath` and `switchSDK` commands
[pico-vscode.git] / src / commands / switchSDK.mts
1 import { compare } from "semver";
2 import { type PicoSDK, detectInstalledSDKs } from "../utils/picoSDKUtil.mjs";
3 import { Command } from "./command.mjs";
4 import { window } from "vscode";
5 import type Settings from "../settings.mjs";
6 import { SettingsKey } from "../settings.mjs";
7 import type UI from "../ui.mjs";
8
9 export default class SwitchSDKCommand extends Command {
10   private _settigs: Settings;
11   private _ui: UI;
12
13   constructor(settings: Settings, ui: UI) {
14     super("switchSDK");
15
16     this._settigs = settings;
17     this._ui = ui;
18   }
19
20   async execute(): Promise<void> {
21     const availableSDKs = (await detectInstalledSDKs()).sort((a, b) =>
22       compare(a.version, b.version)
23     );
24
25     const selectedSDK = await window.showQuickPick<PicoSDK>(availableSDKs, {
26       placeHolder: "Select Pico SDK",
27       canPickMany: false,
28       ignoreFocusOut: false,
29       title: "Switch Pico SDK",
30     });
31
32     if (!selectedSDK) {
33       return;
34     }
35
36     // TODO: maybe ensure workspace settings are used
37     // save selected SDK version to settings
38     await this._settigs.update(SettingsKey.picoSDK, selectedSDK.version);
39     this._ui.updateSDKVersion(selectedSDK.version);
40   }
41 }
This page took 0.032743 seconds and 4 git commands to generate.