Skip to content

Commit 78fcabd

Browse files
authoredApr 13, 2022
Improve Settings Editor experience in a few places (#3919)
* Add type definition so settings editor knows what to do with these settings * Improve `powerShellAdditionalExePaths` setting in settings editor * Search for `powerShellAdditionalExePaths` * Fix up message
1 parent f7654f2 commit 78fcabd

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed
 

‎package.json

+11-21
Original file line numberDiff line numberDiff line change
@@ -549,30 +549,17 @@
549549
},
550550
"powershell.sideBar.CommandExplorerExcludeFilter": {
551551
"type": "array",
552+
"items": {
553+
"type": "string"
554+
},
552555
"default": [],
553556
"description": "Specify array of Modules to exclude from Command Explorer listing."
554557
},
555558
"powershell.powerShellAdditionalExePaths": {
556-
"type": "array",
557-
"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.",
558-
"scope": "machine",
559-
"uniqueItems": true,
560-
"items": {
561-
"type": "object",
562-
"required": [
563-
"versionName",
564-
"exePath"
565-
],
566-
"properties": {
567-
"versionName": {
568-
"type": "string",
569-
"description": "Specifies the version name of this PowerShell executable. The version name can be referenced via the powershell.powerShellDefaultVersion setting."
570-
},
571-
"exePath": {
572-
"type": "string",
573-
"description": "Specifies the path to the PowerShell executable. Typically this is a path to a non-standard install location."
574-
}
575-
}
559+
"type": "object",
560+
"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.",
561+
"additionalProperties": {
562+
"type": "string"
576563
}
577564
},
578565
"powershell.powerShellDefaultVersion": {
@@ -822,7 +809,10 @@
822809
},
823810
"powershell.developer.featureFlags": {
824811
"type": "array",
825-
"default": null,
812+
"items": {
813+
"type": "string"
814+
},
815+
"default": [],
826816
"description": "An array of strings that enable experimental features in the PowerShell extension."
827817
},
828818
"powershell.developer.waitForSessionFileTimeoutSeconds": {

‎src/platform.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class PowerShellExeFinder {
7575
private readonly platformDetails: IPlatformDetails;
7676

7777
// Additional configured PowerShells
78-
private readonly additionalPSExeSettings: Iterable<IPowerShellAdditionalExePathSettings>;
78+
private readonly additionalPSExeSettings: IPowerShellAdditionalExePathSettings;
7979

8080
private winPS: IPossiblePowerShellExe;
8181

@@ -88,10 +88,10 @@ export class PowerShellExeFinder {
8888
*/
8989
constructor(
9090
platformDetails?: IPlatformDetails,
91-
additionalPowerShellExes?: Iterable<IPowerShellAdditionalExePathSettings>) {
91+
additionalPowerShellExes?: IPowerShellAdditionalExePathSettings) {
9292

9393
this.platformDetails = platformDetails || getPlatformDetails();
94-
this.additionalPSExeSettings = additionalPowerShellExes || [];
94+
this.additionalPSExeSettings = additionalPowerShellExes || {};
9595
}
9696

9797
/**
@@ -217,8 +217,13 @@ export class PowerShellExeFinder {
217217
* without checking for their existence.
218218
*/
219219
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
220-
for (const additionalPwshSetting of this.additionalPSExeSettings) {
221-
yield new PossiblePowerShellExe(additionalPwshSetting.exePath, additionalPwshSetting.versionName);
220+
for (const versionName in this.additionalPSExeSettings) {
221+
if (Object.prototype.hasOwnProperty.call(this.additionalPSExeSettings, versionName)) {
222+
const exePath = this.additionalPSExeSettings[versionName];
223+
if (exePath) {
224+
yield new PossiblePowerShellExe(exePath, versionName);
225+
}
226+
}
222227
}
223228
}
224229

‎src/session.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,8 @@ export class SessionManager implements Middleware {
807807
() => { vscode.commands.executeCommand("PowerShell.OpenLogFolder"); }),
808808

809809
new SessionMenuItem(
810-
"Modify 'powerShell.powerShellAdditionalExePaths' in Settings",
811-
() => { vscode.commands.executeCommand("workbench.action.openSettingsJson"); }),
810+
"Modify list of additional PowerShell locations",
811+
() => { vscode.commands.executeCommand("workbench.action.openSettings", "powerShellAdditionalExePaths"); }),
812812
];
813813

814814
vscode

‎src/settings.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export enum CommentType {
2727
}
2828

2929
export interface IPowerShellAdditionalExePathSettings {
30-
versionName: string;
31-
exePath: string;
30+
[versionName: string]: string;
3231
}
3332

3433
export interface IBugReportingSettings {
@@ -79,7 +78,7 @@ export interface IDeveloperSettings {
7978
}
8079

8180
export interface ISettings {
82-
powerShellAdditionalExePaths?: IPowerShellAdditionalExePathSettings[];
81+
powerShellAdditionalExePaths?: IPowerShellAdditionalExePathSettings;
8382
powerShellDefaultVersion?: string;
8483
// This setting is no longer used but is here to assist in cleaning up the users settings.
8584
powerShellExePath?: string;
@@ -225,7 +224,7 @@ export function load(): ISettings {
225224
startAutomatically:
226225
configuration.get<boolean>("startAutomatically", true),
227226
powerShellAdditionalExePaths:
228-
configuration.get<IPowerShellAdditionalExePathSettings[]>("powerShellAdditionalExePaths", undefined),
227+
configuration.get<IPowerShellAdditionalExePathSettings>("powerShellAdditionalExePaths", undefined),
229228
powerShellDefaultVersion:
230229
configuration.get<string>("powerShellDefaultVersion", undefined),
231230
powerShellExePath:

‎test/core/settings.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ describe("Settings module", function () {
2121
});
2222

2323
describe("User-only settings", async function () {
24-
const psExeDetails = [{
25-
versionName: "My PowerShell",
26-
exePath: "dummyPath",
27-
}];
24+
const psExeDetails = {
25+
"My PowerShell": "dummyPath",
26+
};
2827

2928
it("Throws when updating at workspace-level", async function () {
3029
assert.rejects(async () => await Settings.change("powerShellAdditionalExePaths", psExeDetails, false /* workspace-level */));
3130
});
3231

3332
it("Doesn't throw when updating at user-level", async function () {
3433
await Settings.change("powerShellAdditionalExePaths", psExeDetails, true /* user-level */);
35-
assert.strictEqual(Settings.load().powerShellAdditionalExePaths[0].versionName, psExeDetails[0].versionName);
34+
const result = Settings.load().powerShellAdditionalExePaths["My PowerShell"];
35+
assert.notStrictEqual(result, undefined);
36+
assert.strictEqual(result, psExeDetails["My PowerShell"]);
3637
});
3738
});
3839

0 commit comments

Comments
 (0)
Please sign in to comment.