diff --git a/package.json b/package.json index 1fd270ff86..8b051b61e3 100644 --- a/package.json +++ b/package.json @@ -549,30 +549,17 @@ }, "powershell.sideBar.CommandExplorerExcludeFilter": { "type": "array", + "items": { + "type": "string" + }, "default": [], "description": "Specify array of Modules to exclude from Command Explorer listing." }, "powershell.powerShellAdditionalExePaths": { - "type": "array", - "description": "Specifies an array of versionName / exePath pairs where exePath points to a non-standard install location for PowerShell and versionName can be used to reference this path with the powershell.powerShellDefaultVersion setting.", - "scope": "machine", - "uniqueItems": true, - "items": { - "type": "object", - "required": [ - "versionName", - "exePath" - ], - "properties": { - "versionName": { - "type": "string", - "description": "Specifies the version name of this PowerShell executable. The version name can be referenced via the powershell.powerShellDefaultVersion setting." - }, - "exePath": { - "type": "string", - "description": "Specifies the path to the PowerShell executable. Typically this is a path to a non-standard install location." - } - } + "type": "object", + "description": "Specifies a list of versionName / exePath pairs where exePath points to a non-standard install location for PowerShell and versionName can be used to reference this path with the powershell.powerShellDefaultVersion setting.", + "additionalProperties": { + "type": "string" } }, "powershell.powerShellDefaultVersion": { @@ -822,7 +809,10 @@ }, "powershell.developer.featureFlags": { "type": "array", - "default": null, + "items": { + "type": "string" + }, + "default": [], "description": "An array of strings that enable experimental features in the PowerShell extension." }, "powershell.developer.waitForSessionFileTimeoutSeconds": { diff --git a/src/platform.ts b/src/platform.ts index 9aee1e5d1a..b75e302f45 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -75,7 +75,7 @@ export class PowerShellExeFinder { private readonly platformDetails: IPlatformDetails; // Additional configured PowerShells - private readonly additionalPSExeSettings: Iterable; + private readonly additionalPSExeSettings: IPowerShellAdditionalExePathSettings; private winPS: IPossiblePowerShellExe; @@ -88,10 +88,10 @@ export class PowerShellExeFinder { */ constructor( platformDetails?: IPlatformDetails, - additionalPowerShellExes?: Iterable) { + additionalPowerShellExes?: IPowerShellAdditionalExePathSettings) { this.platformDetails = platformDetails || getPlatformDetails(); - this.additionalPSExeSettings = additionalPowerShellExes || []; + this.additionalPSExeSettings = additionalPowerShellExes || {}; } /** @@ -217,8 +217,13 @@ export class PowerShellExeFinder { * without checking for their existence. */ private *enumerateAdditionalPowerShellInstallations(): Iterable { - for (const additionalPwshSetting of this.additionalPSExeSettings) { - yield new PossiblePowerShellExe(additionalPwshSetting.exePath, additionalPwshSetting.versionName); + for (const versionName in this.additionalPSExeSettings) { + if (Object.prototype.hasOwnProperty.call(this.additionalPSExeSettings, versionName)) { + const exePath = this.additionalPSExeSettings[versionName]; + if (exePath) { + yield new PossiblePowerShellExe(exePath, versionName); + } + } } } diff --git a/src/session.ts b/src/session.ts index 6ac6169f5c..3a89464d17 100644 --- a/src/session.ts +++ b/src/session.ts @@ -807,8 +807,8 @@ export class SessionManager implements Middleware { () => { vscode.commands.executeCommand("PowerShell.OpenLogFolder"); }), new SessionMenuItem( - "Modify 'powerShell.powerShellAdditionalExePaths' in Settings", - () => { vscode.commands.executeCommand("workbench.action.openSettingsJson"); }), + "Modify list of additional PowerShell locations", + () => { vscode.commands.executeCommand("workbench.action.openSettings", "powerShellAdditionalExePaths"); }), ]; vscode diff --git a/src/settings.ts b/src/settings.ts index c15cb0e9cd..d1c648bff8 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -27,8 +27,7 @@ export enum CommentType { } export interface IPowerShellAdditionalExePathSettings { - versionName: string; - exePath: string; + [versionName: string]: string; } export interface IBugReportingSettings { @@ -79,7 +78,7 @@ export interface IDeveloperSettings { } export interface ISettings { - powerShellAdditionalExePaths?: IPowerShellAdditionalExePathSettings[]; + powerShellAdditionalExePaths?: IPowerShellAdditionalExePathSettings; powerShellDefaultVersion?: string; // This setting is no longer used but is here to assist in cleaning up the users settings. powerShellExePath?: string; @@ -225,7 +224,7 @@ export function load(): ISettings { startAutomatically: configuration.get("startAutomatically", true), powerShellAdditionalExePaths: - configuration.get("powerShellAdditionalExePaths", undefined), + configuration.get("powerShellAdditionalExePaths", undefined), powerShellDefaultVersion: configuration.get("powerShellDefaultVersion", undefined), powerShellExePath: diff --git a/test/core/settings.test.ts b/test/core/settings.test.ts index b938aadf0e..1143f8333f 100644 --- a/test/core/settings.test.ts +++ b/test/core/settings.test.ts @@ -21,10 +21,9 @@ describe("Settings module", function () { }); describe("User-only settings", async function () { - const psExeDetails = [{ - versionName: "My PowerShell", - exePath: "dummyPath", - }]; + const psExeDetails = { + "My PowerShell": "dummyPath", + }; it("Throws when updating at workspace-level", async function () { assert.rejects(async () => await Settings.change("powerShellAdditionalExePaths", psExeDetails, false /* workspace-level */)); @@ -32,7 +31,9 @@ describe("Settings module", function () { it("Doesn't throw when updating at user-level", async function () { await Settings.change("powerShellAdditionalExePaths", psExeDetails, true /* user-level */); - assert.strictEqual(Settings.load().powerShellAdditionalExePaths[0].versionName, psExeDetails[0].versionName); + const result = Settings.load().powerShellAdditionalExePaths["My PowerShell"]; + assert.notStrictEqual(result, undefined); + assert.strictEqual(result, psExeDetails["My PowerShell"]); }); });