|
| 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 | +} |
0 commit comments