@@ -313,34 +313,42 @@ function getWorkspaceSettingsWithDefaults<TSettings>(
313
313
return defaultSettings ;
314
314
}
315
315
316
+ // We don't want to query the user more than once, so this is idempotent.
317
+ let hasPrompted : boolean = false ;
318
+
316
319
export async function validateCwdSetting ( ) : Promise < string > {
317
- let cwd : string = vscode . workspace . getConfiguration ( utils . PowerShellLanguageId ) . get < string > ( "cwd" , null ) ;
320
+ let cwd : string = vscode . workspace . getConfiguration ( utils . PowerShellLanguageId ) . get < string > ( "cwd" , undefined ) ;
318
321
319
322
// Only use the cwd setting if it exists.
320
323
if ( await utils . checkIfDirectoryExists ( cwd ) ) {
321
324
return cwd ;
322
- } else {
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 ) {
332
- const options : vscode . WorkspaceFolderPickOptions = {
333
- placeHolder : "Select a folder to use as the PowerShell extension's working directory." ,
334
- }
335
- cwd = ( await vscode . window . showWorkspaceFolderPick ( options ) ) ?. uri . fsPath ;
336
- // Save the picked 'cwd' to the workspace settings.
337
- await change ( "cwd" , cwd ) ;
325
+ }
326
+
327
+ // If there is no workspace, or there is but it has no folders, fallback.
328
+ if ( vscode . workspace . workspaceFolders === undefined
329
+ || vscode . workspace . workspaceFolders ?. length === 0 ) {
330
+ cwd = undefined ;
331
+ // If there is exactly one workspace folder, use that.
332
+ } if ( vscode . workspace . workspaceFolders ?. length === 1 ) {
333
+ cwd = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
334
+ // If there is more than one workspace folder, prompt the user once.
335
+ } else if ( vscode . workspace . workspaceFolders ?. length > 1 && ! hasPrompted ) {
336
+ hasPrompted = true ;
337
+ const options : vscode . WorkspaceFolderPickOptions = {
338
+ placeHolder : "Select a folder to use as the PowerShell extension's working directory." ,
338
339
}
339
- // If there were no workspace folders, or somehow they don't exist, use
340
- // the home directory.
341
- if ( cwd === undefined || ! await utils . checkIfDirectoryExists ( cwd ) ) {
342
- return os . homedir ( ) ;
340
+ cwd = ( await vscode . window . showWorkspaceFolderPick ( options ) ) ?. uri . fsPath ;
341
+ // Save the picked 'cwd' to the workspace settings.
342
+ // We have to check again because the user may not have picked.
343
+ if ( await utils . checkIfDirectoryExists ( cwd ) ) {
344
+ await change ( "cwd" , cwd ) ;
343
345
}
344
- return cwd ;
345
346
}
347
+
348
+ // If there were no workspace folders, or somehow they don't exist, use
349
+ // the home directory.
350
+ if ( cwd === undefined || ! await utils . checkIfDirectoryExists ( cwd ) ) {
351
+ return os . homedir ( ) ;
352
+ }
353
+ return cwd ;
346
354
}
0 commit comments