Skip to content

Commit d3978e7

Browse files
committed
feat(CleanZephyrCommand): Add new Command to remove zephyr workspace
Signed-off-by: paulober <[email protected]>
1 parent 3c95db7 commit d3978e7

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@
285285
"title": "Get git path",
286286
"category": "Raspberry Pi Pico",
287287
"enablement": "false"
288+
},
289+
{
290+
"command": "raspberry-pi-pico.cleanZephyr",
291+
"title": "Remove Zephyr workspace",
292+
"category": "Raspberry Pi Pico"
288293
}
289294
],
290295
"configuration": {

src/commands/cleanZephyr.mts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { commands, Uri, window, workspace } from "vscode";
2+
import { CLEAN_ZEPHYR } from "./cmdIds.mjs";
3+
import { Command, extensionName } from "./command.mjs";
4+
import Logger from "../logger.mjs";
5+
import { homedir } from "os";
6+
import { unknownErrorToString } from "../utils/errorHelper.mjs";
7+
import State from "../state.mjs";
8+
9+
export class CleanZephyrCommand extends Command {
10+
private _logger: Logger = new Logger("CleanZephyrCommand");
11+
12+
public constructor() {
13+
super(CLEAN_ZEPHYR);
14+
}
15+
16+
public override async execute(): Promise<void> {
17+
const zephyrWorkspaceUri = Uri.joinPath(
18+
Uri.file(homedir()),
19+
".pico-sdk",
20+
"zephyr_workspace"
21+
);
22+
23+
try {
24+
await workspace.fs.stat(zephyrWorkspaceUri);
25+
26+
await workspace.fs.delete(zephyrWorkspaceUri, { recursive: true });
27+
this._logger.info(
28+
`Zephyr workspace at ${zephyrWorkspaceUri.fsPath} has been removed.`
29+
);
30+
if (State.getInstance().isZephyrProject) {
31+
const answer = await window.showInformationMessage(
32+
"Zephyr workspace has been removed. " +
33+
"Reload the window to reinitialize the Zephyr workspace.",
34+
"Reload Window"
35+
);
36+
37+
if (answer === "Reload Window") {
38+
await commands.executeCommand("workbench.action.reloadWindow");
39+
}
40+
} else {
41+
void window.showInformationMessage(
42+
"Zephyr workspace has been removed."
43+
);
44+
}
45+
} catch (e) {
46+
this._logger.warn(
47+
`Zephyr workspace at ${zephyrWorkspaceUri.fsPath} ` +
48+
`does not exist or could not be accessed: ${unknownErrorToString(e)}`
49+
);
50+
void window.showInformationMessage(
51+
"A Zephyr workspace does not exist or could not be accessed."
52+
);
53+
}
54+
}
55+
}

src/commands/cmdIds.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ export const UNINSTALL_PICO_SDK = "uninstallPicoSDK";
4747
export const UPDATE_OPENOCD = "updateOpenOCD";
4848

4949
export const OPEN_UNINSTALLER = "openUninstaller";
50+
51+
export const CLEAN_ZEPHYR = "cleanZephyr";

src/extension.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ import LastUsedDepsStore from "./utils/lastUsedDeps.mjs";
126126
import { getWebviewOptions } from "./webview/sharedFunctions.mjs";
127127
import { UninstallerPanel } from "./webview/uninstallerPanel.mjs";
128128
import OpenUninstallerCommand from "./commands/openUninstaller.mjs";
129+
import { CleanZephyrCommand } from "./commands/cleanZephyr.mjs";
129130

130131
export async function activate(context: ExtensionContext): Promise<void> {
131132
Logger.info(LoggerSource.extension, "Extension activation triggered");
@@ -186,6 +187,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
186187
new SbomTargetPathReleaseCommand(),
187188
new OpenUninstallerCommand(context.extensionUri),
188189
new GetGitPathCommand(settings),
190+
new CleanZephyrCommand(),
189191
];
190192

191193
// register all command handlers

0 commit comments

Comments
 (0)