Skip to content

Commit f695b82

Browse files
authored
Merge pull request #218 from raspberrypi/add-last-used-store
2 parents fb9437f + eab856a commit f695b82

22 files changed

+1843
-133
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"onWebviewPanel:newPicoProject",
6868
"onWebviewPanel:newPicoMicroPythonProject",
6969
"onWebviewPanel:newPicoRustProject",
70-
"onWebviewPanel:newPicoZephyrProject"
70+
"onWebviewPanel:newPicoZephyrProject",
71+
"onWebviewPanel:uninstaller"
7172
],
7273
"contributes": {
7374
"commands": [
@@ -273,6 +274,11 @@
273274
"title": "Get Zephyr SDK path",
274275
"category": "Raspberry Pi Pico",
275276
"enablement": "false"
277+
},
278+
{
279+
"command": "raspberry-pi-pico.openUninstaller",
280+
"title": "Open Uninstaller",
281+
"category": "Raspberry Pi Pico"
276282
}
277283
],
278284
"configuration": {

src/commands/cmdIds.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ export const SWITCH_SDK = "switchSDK";
4444
export const UNINSTALL_PICO_SDK = "uninstallPicoSDK";
4545

4646
export const UPDATE_OPENOCD = "updateOpenOCD";
47+
48+
export const OPEN_UNINSTALLER = "openUninstaller";

src/commands/openUninstaller.mts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Uri } from "vscode";
2+
import { Command } from "./command.mjs";
3+
import { OPEN_UNINSTALLER } from "./cmdIds.mjs";
4+
import { UninstallerPanel } from "../webview/uninstallerPanel.mjs";
5+
6+
export default class OpenUninstallerCommand extends Command {
7+
private readonly _extensionUri: Uri;
8+
9+
constructor(extensionUri: Uri) {
10+
super(OPEN_UNINSTALLER);
11+
12+
this._extensionUri = extensionUri;
13+
}
14+
15+
execute(): void {
16+
UninstallerPanel.createOrShow(this._extensionUri);
17+
}
18+
}

src/commands/switchSDK.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
window,
66
workspace,
77
commands,
8-
type WorkspaceFolder,
98
} from "vscode";
109
import type UI from "../ui.mjs";
1110
import { updateVSCodeStaticConfigs } from "../utils/vscodeConfigUtil.mjs";

src/extension.mts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ import {
6767
downloadAndInstallOpenOCD,
6868
} from "./utils/download.mjs";
6969
import { getSupportedToolchains } from "./utils/toolchainUtil.mjs";
70-
import {
71-
NewProjectPanel,
72-
getWebviewOptions,
73-
} from "./webview/newProjectPanel.mjs";
70+
import { NewProjectPanel } from "./webview/newProjectPanel.mjs";
7471
import GithubApiCache from "./utils/githubApiCache.mjs";
7572
import ClearGithubApiCacheCommand from "./commands/clearGithubApiCache.mjs";
7673
import { ContextKeys } from "./contextKeys.mjs";
@@ -124,6 +121,10 @@ import {
124121
ZEPHYR_PICO_W,
125122
} from "./models/zephyrBoards.mjs";
126123
import { NewZephyrProjectPanel } from "./webview/newZephyrProjectPanel.mjs";
124+
import LastUsedDepsStore from "./utils/lastUsedDeps.mjs";
125+
import { getWebviewOptions } from "./webview/sharedFunctions.mjs";
126+
import { UninstallerPanel } from "./webview/uninstallerPanel.mjs";
127+
import OpenUninstallerCommand from "./commands/openUninstaller.mjs";
127128

128129
export async function activate(context: ExtensionContext): Promise<void> {
129130
Logger.info(LoggerSource.extension, "Extension activation triggered");
@@ -134,6 +135,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
134135
context.extension.packageJSON as PackageJSON
135136
);
136137
GithubApiCache.createInstance(context);
138+
LastUsedDepsStore.instance.setup(context.globalState);
137139

138140
const picoProjectActivityBarProvider = new PicoProjectActivityBar();
139141
const ui = new UI(picoProjectActivityBarProvider);
@@ -181,6 +183,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
181183
new UpdateOpenOCDCommand(),
182184
new SbomTargetPathDebugCommand(),
183185
new SbomTargetPathReleaseCommand(),
186+
new OpenUninstallerCommand(context.extensionUri),
184187
];
185188

186189
// register all command handlers
@@ -241,6 +244,17 @@ export async function activate(context: ExtensionContext): Promise<void> {
241244
})
242245
);
243246

247+
context.subscriptions.push(
248+
window.registerWebviewPanelSerializer(UninstallerPanel.viewType, {
249+
// eslint-disable-next-line @typescript-eslint/require-await
250+
async deserializeWebviewPanel(webviewPanel: WebviewPanel): Promise<void> {
251+
// Reset the webview options so we use latest uri for `localResourceRoots`.
252+
webviewPanel.webview.options = getWebviewOptions(context.extensionUri);
253+
UninstallerPanel.revive(webviewPanel, context.extensionUri);
254+
},
255+
})
256+
);
257+
244258
context.subscriptions.push(
245259
window.registerTreeDataProvider(
246260
PicoProjectActivityBar.viewType,

src/logger.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export enum LoggerSource {
4646
projectRust = "projectRust",
4747
zephyrSetup = "setupZephyr",
4848
projectZephyr = "projectZephyr",
49+
uninstallUtil = "uninstallUtil",
4950
}
5051

5152
/**

src/models/dependency.mts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export type DepId =
2+
| "pico-sdk"
3+
| "arm-toolchain"
4+
| "riscv-toolchain"
5+
| "ninja"
6+
| "cmake"
7+
| "embedded-python" // windows-only
8+
| "git" // windows-only
9+
| "openocd"
10+
| "7zip" // windows-only
11+
| "pico-sdk-tools"
12+
| "picotool"
13+
| "zephyr";
14+
15+
export interface DependencyMeta {
16+
id: DepId;
17+
label: string;
18+
platforms?: NodeJS.Platform[]; // omit = all
19+
versioned?: boolean; // default true
20+
}
21+
22+
export const ALL_DEPS: DependencyMeta[] = [
23+
{ id: "pico-sdk", label: "Pico SDK" },
24+
{ id: "arm-toolchain", label: "Arm GNU Toolchain" },
25+
{ id: "riscv-toolchain", label: "RISC-V GNU Toolchain" },
26+
{ id: "ninja", label: "Ninja" },
27+
{ id: "cmake", label: "CMake" },
28+
{ id: "embedded-python", label: "Embedded Python", platforms: ["win32"] },
29+
{ id: "git", label: "Git", platforms: ["win32"] },
30+
{ id: "openocd", label: "OpenOCD" },
31+
{ id: "7zip", label: "7-Zip", platforms: ["win32"], versioned: false },
32+
{ id: "pico-sdk-tools", label: "Pico SDK Tools" },
33+
{ id: "picotool", label: "Picotool" },
34+
{ id: "zephyr", label: "Zephyr" },
35+
];
36+
37+
// version -> YYYY-MM-DD (local)
38+
export type VersionMap = Record<string, string>;
39+
// dep -> VersionMap
40+
export type DepVersionDb = Record<DepId, VersionMap>;
41+
42+
export const INSTALL_ROOT_ALIAS: Partial<Record<DepId, string>> = {
43+
// eslint-disable-next-line @typescript-eslint/naming-convention
44+
"pico-sdk": "sdk",
45+
// eslint-disable-next-line @typescript-eslint/naming-convention
46+
"pico-sdk-tools": "tools",
47+
// eslint-disable-next-line @typescript-eslint/naming-convention
48+
"arm-toolchain": "toolchain",
49+
// eslint-disable-next-line @typescript-eslint/naming-convention
50+
"riscv-toolchain": "toolchain",
51+
zephyr: "zephyr_workspace",
52+
// others default to their depId
53+
};

src/ui.mts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ enum StatusBarItemKey {
1919

2020
const STATUS_BAR_ITEMS: {
2121
[key: string]: {
22+
name: string;
2223
text: string;
2324
rustText?: string;
2425
zephyrText?: string;
2526
command: string;
2627
tooltip: string;
28+
rustTooltip?: string;
2729
zephyrTooltip?: string;
2830
rustSupport: boolean;
2931
zephyrSupport: boolean;
3032
};
3133
} = {
3234
[StatusBarItemKey.compile]: {
35+
name: "Raspberry Pi Pico - Compile Project",
3336
// alt. "$(gear) Compile"
3437
text: "$(file-binary) Compile",
3538
command: `${extensionName}.${COMPILE_PROJECT}`,
@@ -38,6 +41,7 @@ const STATUS_BAR_ITEMS: {
3841
zephyrSupport: true,
3942
},
4043
[StatusBarItemKey.run]: {
44+
name: "Raspberry Pi Pico - Run Project",
4145
// alt. "$(gear) Compile"
4246
text: "$(run) Run",
4347
command: `${extensionName}.${RUN_PROJECT}`,
@@ -46,6 +50,7 @@ const STATUS_BAR_ITEMS: {
4650
zephyrSupport: true,
4751
},
4852
[StatusBarItemKey.picoSDKQuickPick]: {
53+
name: "Raspberry Pi Pico - Select SDK Version",
4954
text: "Pico SDK: <version>",
5055
zephyrText: "Zephyr version: <version>",
5156
command: `${extensionName}.${SWITCH_SDK}`,
@@ -55,10 +60,12 @@ const STATUS_BAR_ITEMS: {
5560
zephyrSupport: true,
5661
},
5762
[StatusBarItemKey.picoBoardQuickPick]: {
63+
name: "Raspberry Pi Pico - Select Board",
5864
text: "Board: <board>",
5965
rustText: "Chip: <chip>",
6066
command: `${extensionName}.${SWITCH_BOARD}`,
61-
tooltip: "Select Chip",
67+
tooltip: "Select board",
68+
rustTooltip: "Select Chip",
6269
rustSupport: true,
6370
zephyrSupport: true,
6471
},
@@ -78,6 +85,7 @@ export default class UI {
7885
Object.entries(STATUS_BAR_ITEMS).forEach(([key, value]) => {
7986
this._items[key] = this.createStatusBarItem(
8087
key,
88+
value.name,
8189
value.text,
8290
value.command,
8391
value.tooltip
@@ -102,6 +110,13 @@ export default class UI {
102110
if (STATUS_BAR_ITEMS[item.id].zephyrTooltip) {
103111
item.tooltip = STATUS_BAR_ITEMS[item.id].zephyrTooltip;
104112
}
113+
} else if (isRustProject) {
114+
if (STATUS_BAR_ITEMS[item.id].rustText) {
115+
item.text = STATUS_BAR_ITEMS[item.id].rustText!;
116+
}
117+
if (STATUS_BAR_ITEMS[item.id].rustTooltip) {
118+
item.tooltip = STATUS_BAR_ITEMS[item.id].rustTooltip;
119+
}
105120
}
106121
item.show();
107122
});
@@ -160,11 +175,13 @@ export default class UI {
160175

161176
private createStatusBarItem(
162177
key: string,
178+
name: string,
163179
text: string,
164180
command: string,
165181
tooltip: string
166182
): StatusBarItem {
167183
const item = window.createStatusBarItem(key, StatusBarAlignment.Right);
184+
item.name = name;
168185
item.text = text;
169186
item.command = command;
170187
item.tooltip = tooltip;

0 commit comments

Comments
 (0)