File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 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> {
320320 if ( await utils . checkIfDirectoryExists ( cwd ) ) {
321321 return cwd ;
322322 } 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 ) {
325332 const options : vscode . WorkspaceFolderPickOptions = {
326333 placeHolder : "Select a folder to use as the PowerShell extension's working directory." ,
327334 }
328335 cwd = ( await vscode . window . showWorkspaceFolderPick ( options ) ) ?. uri . fsPath ;
329336 // Save the picked 'cwd' to the workspace settings.
330337 await change ( "cwd" , cwd ) ;
331- } else {
332- cwd = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
333338 }
334339 // If there were no workspace folders, or somehow they don't exist, use
335340 // the home directory.
You can’t perform that action at this time.
0 commit comments