()
| 82 | * Displays an input box allowing the user to enter a custom path |
| 83 | */ |
| 84 | export async function promptForCustomStoragePath(): Promise<void> { |
| 85 | if (!vscode.window || !vscode.workspace) { |
| 86 | console.error("VS Code API not available") |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | let currentPath = "" |
| 91 | try { |
| 92 | const currentConfig = vscode.workspace.getConfiguration(Package.name) |
| 93 | currentPath = currentConfig.get<string>("customStoragePath", "") |
| 94 | } catch (error) { |
| 95 | console.error("Could not access configuration") |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | const result = await vscode.window.showInputBox({ |
| 100 | value: currentPath, |
| 101 | placeHolder: t("common:storage.path_placeholder"), |
| 102 | prompt: t("common:storage.prompt_custom_path"), |
| 103 | validateInput: (input) => { |
| 104 | if (!input) { |
| 105 | return null // Allow empty value (use default path) |
| 106 | } |
| 107 | |
| 108 | try { |
| 109 | // Validate path format |
| 110 | path.parse(input) |
| 111 | |
| 112 | // Check if path is absolute |
| 113 | if (!path.isAbsolute(input)) { |
| 114 | return t("common:storage.enter_absolute_path") |
| 115 | } |
| 116 | |
| 117 | return null // Path format is valid |
| 118 | } catch (e) { |
| 119 | return t("common:storage.enter_valid_path") |
| 120 | } |
| 121 | }, |
| 122 | }) |
| 123 | |
| 124 | // If user canceled the operation, result will be undefined |
| 125 | if (result !== undefined) { |
| 126 | try { |
| 127 | const currentConfig = vscode.workspace.getConfiguration(Package.name) |
| 128 | await currentConfig.update("customStoragePath", result, vscode.ConfigurationTarget.Global) |
| 129 | |
| 130 | if (result) { |
| 131 | try { |
| 132 | // Test if path is accessible |
| 133 | await fs.mkdir(result, { recursive: true }) |
| 134 | await fs.access(result, fsConstants.R_OK | fsConstants.W_OK | fsConstants.X_OK) |
| 135 | vscode.window.showInformationMessage(t("common:info.custom_storage_path_set", { path: result })) |
| 136 | } catch (error) { |
| 137 | vscode.window.showErrorMessage( |
| 138 | t("common:errors.cannot_access_path", { |
| 139 | path: result, |
| 140 | error: error instanceof Error ? error.message : String(error), |
| 141 | }), |
no test coverage detected