Skip to content

Fix edge case for workspaces defined with zero folders #4104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,21 @@ export async function validateCwdSetting(): Promise<string> {
if (await utils.checkIfDirectoryExists(cwd)) {
return cwd;
} else {
// Otherwise use a workspace folder, prompting if necessary.
if (vscode.workspace.workspaceFolders?.length > 1) {
// If there is no workspace, or there is but it has no folders, fallback.
if (vscode.workspace.workspaceFolders === undefined
|| vscode.workspace.workspaceFolders?.length === 0) {
cwd = undefined;
// If there is exactly one workspace folder, use that.
} if (vscode.workspace.workspaceFolders?.length === 1) {
cwd = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
// If there is more than one workspace folder, prompt the user.
} else if (vscode.workspace.workspaceFolders?.length > 1) {
const options: vscode.WorkspaceFolderPickOptions = {
placeHolder: "Select a folder to use as the PowerShell extension's working directory.",
}
cwd = (await vscode.window.showWorkspaceFolderPick(options))?.uri.fsPath;
// Save the picked 'cwd' to the workspace settings.
await change("cwd", cwd);
} else {
cwd = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
}
// If there were no workspace folders, or somehow they don't exist, use
// the home directory.
Expand Down