Skip to content

Show warning when additional PowerShell is not found #4242

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
Nov 3, 2022
Merged
Show file tree
Hide file tree
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
30 changes: 11 additions & 19 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as os from "os";
import * as path from "path";
import * as process from "process";
import { integer } from "vscode-languageserver-protocol";
import { Logger } from "./logging";
import { PowerShellAdditionalExePathSettings } from "./settings";

// This uses require so we can rewire it in unit tests!
Expand Down Expand Up @@ -70,19 +71,9 @@ export function getPlatformDetails(): IPlatformDetails {
export class PowerShellExeFinder {
// This is required, since parseInt("7-preview") will return 7.
private static IntRegex = /^\d+$/;

private static PwshMsixRegex = /^Microsoft.PowerShell_.*/;

private static PwshPreviewMsixRegex = /^Microsoft.PowerShellPreview_.*/;

// The platform details descriptor for the platform we're on
private readonly platformDetails: IPlatformDetails;

// Additional configured PowerShells
private readonly additionalPSExeSettings: PowerShellAdditionalExePathSettings;

private winPS: IPossiblePowerShellExe | undefined;

private alternateBitnessWinPS: IPossiblePowerShellExe | undefined;

/**
Expand All @@ -91,12 +82,11 @@ export class PowerShellExeFinder {
* @param additionalPowerShellExes Additional PowerShell installations as configured in the settings.
*/
constructor(
platformDetails?: IPlatformDetails,
additionalPowerShellExes?: PowerShellAdditionalExePathSettings) {

this.platformDetails = platformDetails ?? getPlatformDetails();
this.additionalPSExeSettings = additionalPowerShellExes ?? {};
}
// The platform details descriptor for the platform we're on
private platformDetails: IPlatformDetails,
// Additional configured PowerShells
private additionalPowerShellExes: PowerShellAdditionalExePathSettings,
private logger: Logger) { }

/**
* Returns the first available PowerShell executable found in the search order.
Expand Down Expand Up @@ -159,6 +149,8 @@ export class PowerShellExeFinder {
for (const additionalPwsh of this.enumerateAdditionalPowerShellInstallations()) {
if (await additionalPwsh.exists()) {
yield additionalPwsh;
} else {
void this.logger.writeAndShowWarning(`Additional PowerShell '${additionalPwsh.displayName}' not found at '${additionalPwsh.exePath}'!`);
}
}
}
Expand Down Expand Up @@ -226,9 +218,9 @@ export class PowerShellExeFinder {
* without checking for their existence.
*/
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
for (const versionName in this.additionalPSExeSettings) {
if (Object.prototype.hasOwnProperty.call(this.additionalPSExeSettings, versionName)) {
const exePath = this.additionalPSExeSettings[versionName];
for (const versionName in this.additionalPowerShellExes) {
if (Object.prototype.hasOwnProperty.call(this.additionalPowerShellExes, versionName)) {
const exePath = this.additionalPowerShellExes[versionName];
if (exePath) {
yield new PossiblePowerShellExe(exePath, versionName);
}
Expand Down
6 changes: 4 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ export class SessionManager implements Middleware {
private async findPowerShell(): Promise<IPowerShellExeDetails | undefined> {
const powershellExeFinder = new PowerShellExeFinder(
this.platformDetails,
this.sessionSettings.powerShellAdditionalExePaths);
this.sessionSettings.powerShellAdditionalExePaths,
this.logger);

let foundPowerShell: IPowerShellExeDetails | undefined;
try {
Expand Down Expand Up @@ -837,7 +838,8 @@ Type 'help' to get help.
private async showSessionMenu() {
const powershellExeFinder = new PowerShellExeFinder(
this.platformDetails,
this.sessionSettings.powerShellAdditionalExePaths);
this.sessionSettings.powerShellAdditionalExePaths,
this.logger);
const availablePowerShellExes = await powershellExeFinder.getAllAvailablePowerShellInstallations();

let sessionText: string;
Expand Down