(
logger: ILogger | undefined,
)
| 223 | let hasChosen = false; |
| 224 | let chosenWorkspace: vscode.WorkspaceFolder | undefined = undefined; |
| 225 | export async function getChosenWorkspace( |
| 226 | logger: ILogger | undefined, |
| 227 | ): Promise<vscode.WorkspaceFolder | undefined> { |
| 228 | if (hasChosen) { |
| 229 | return chosenWorkspace; |
| 230 | } |
| 231 | |
| 232 | // If there is no workspace, or there is but it has no folders, fallback. |
| 233 | if ( |
| 234 | vscode.workspace.workspaceFolders === undefined || |
| 235 | vscode.workspace.workspaceFolders.length === 0 |
| 236 | ) { |
| 237 | chosenWorkspace = undefined; |
| 238 | // If there is exactly one workspace folder, use that. |
| 239 | } else if (vscode.workspace.workspaceFolders.length === 1) { |
| 240 | chosenWorkspace = vscode.workspace.workspaceFolders[0]; |
| 241 | // If there is more than one workspace folder, prompt the user once. |
| 242 | } else if (vscode.workspace.workspaceFolders.length > 1) { |
| 243 | const options: vscode.WorkspaceFolderPickOptions = { |
| 244 | placeHolder: |
| 245 | "Select a workspace folder to use for the PowerShell Extension.", |
| 246 | }; |
| 247 | |
| 248 | chosenWorkspace = await vscode.window.showWorkspaceFolderPick(options); |
| 249 | |
| 250 | logger?.writeDebug( |
| 251 | `User selected workspace: '${chosenWorkspace?.name}'`, |
| 252 | ); |
| 253 | if (chosenWorkspace === undefined) { |
| 254 | chosenWorkspace = vscode.workspace.workspaceFolders[0]; |
| 255 | } else { |
| 256 | const response = await vscode.window.showInformationMessage( |
| 257 | `Would you like to save this choice by setting this workspace's 'powershell.cwd' value to '${chosenWorkspace.name}'?`, |
| 258 | "Yes", |
| 259 | "No", |
| 260 | ); |
| 261 | |
| 262 | if (response === "Yes") { |
| 263 | await changeSetting( |
| 264 | "cwd", |
| 265 | chosenWorkspace.name, |
| 266 | vscode.ConfigurationTarget.Workspace, |
| 267 | logger, |
| 268 | ); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // NOTE: We don't rely on checking if `chosenWorkspace` is undefined because |
| 274 | // that may be the case if the user dismissed the prompt, and we don't want |
| 275 | // to show it again this session. |
| 276 | hasChosen = true; |
| 277 | return chosenWorkspace; |
| 278 | } |
| 279 | |
| 280 | export async function validateCwdSetting( |
| 281 | logger: ILogger | undefined, |
no test coverage detected