Skip to content

Improve Settings Editor experience in a few places #3919

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
Show file tree
Hide file tree
Changes from 2 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
32 changes: 11 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
15 changes: 10 additions & 5 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class PowerShellExeFinder {
private readonly platformDetails: IPlatformDetails;

// Additional configured PowerShells
private readonly additionalPSExeSettings: Iterable<IPowerShellAdditionalExePathSettings>;
private readonly additionalPSExeSettings: IPowerShellAdditionalExePathSettings;

private winPS: IPossiblePowerShellExe;

Expand All @@ -88,10 +88,10 @@ export class PowerShellExeFinder {
*/
constructor(
platformDetails?: IPlatformDetails,
additionalPowerShellExes?: Iterable<IPowerShellAdditionalExePathSettings>) {
additionalPowerShellExes?: IPowerShellAdditionalExePathSettings) {

this.platformDetails = platformDetails || getPlatformDetails();
this.additionalPSExeSettings = additionalPowerShellExes || [];
this.additionalPSExeSettings = additionalPowerShellExes || {};
}

/**
Expand Down Expand Up @@ -217,8 +217,13 @@ export class PowerShellExeFinder {
* without checking for their existence.
*/
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
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);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ export class SessionManager implements Middleware {

new SessionMenuItem(
"Modify 'powerShell.powerShellAdditionalExePaths' in Settings",
() => { vscode.commands.executeCommand("workbench.action.openSettingsJson"); }),
() => { vscode.commands.executeCommand("workbench.action.openSettings", "powershell.powerShellAdditionalExePaths"); }),
];

vscode
Expand Down
7 changes: 3 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export enum CommentType {
}

export interface IPowerShellAdditionalExePathSettings {
versionName: string;
exePath: string;
[versionName: string]: string;
}

export interface IBugReportingSettings {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -225,7 +224,7 @@ export function load(): ISettings {
startAutomatically:
configuration.get<boolean>("startAutomatically", true),
powerShellAdditionalExePaths:
configuration.get<IPowerShellAdditionalExePathSettings[]>("powerShellAdditionalExePaths", undefined),
configuration.get<IPowerShellAdditionalExePathSettings>("powerShellAdditionalExePaths", undefined),
powerShellDefaultVersion:
configuration.get<string>("powerShellDefaultVersion", undefined),
powerShellExePath:
Expand Down
11 changes: 6 additions & 5 deletions test/core/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ 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 */));
});

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"]);
});
});

Expand Down