File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -320,16 +320,21 @@ export async function validateCwdSetting(): Promise<string> {
320
320
if ( await utils . checkIfDirectoryExists ( cwd ) ) {
321
321
return cwd ;
322
322
} else {
323
- // Otherwise use a workspace folder, prompting if necessary.
324
- if ( vscode . workspace . workspaceFolders ?. length > 1 ) {
323
+ // If there is no workspace, or there is but it has no folders, fallback.
324
+ if ( vscode . workspace . workspaceFolders === undefined
325
+ || vscode . workspace . workspaceFolders ?. length === 0 ) {
326
+ cwd = undefined ;
327
+ // If there is exactly one workspace folder, use that.
328
+ } if ( vscode . workspace . workspaceFolders ?. length === 1 ) {
329
+ cwd = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
330
+ // If there is more than one workspace folder, prompt the user.
331
+ } else if ( vscode . workspace . workspaceFolders ?. length > 1 ) {
325
332
const options : vscode . WorkspaceFolderPickOptions = {
326
333
placeHolder : "Select a folder to use as the PowerShell extension's working directory." ,
327
334
}
328
335
cwd = ( await vscode . window . showWorkspaceFolderPick ( options ) ) ?. uri . fsPath ;
329
336
// Save the picked 'cwd' to the workspace settings.
330
337
await change ( "cwd" , cwd ) ;
331
- } else {
332
- cwd = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
333
338
}
334
339
// If there were no workspace folders, or somehow they don't exist, use
335
340
// the home directory.
You can’t perform that action at this time.
0 commit comments