Skip to content

Commit 87f6fa9

Browse files
committed
Show warning when additional PowerShell is not found
1 parent 0f422a0 commit 87f6fa9

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/platform.ts

+11-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as os from "os";
55
import * as path from "path";
66
import * as process from "process";
77
import { integer } from "vscode-languageserver-protocol";
8+
import { Logger } from "./logging";
89
import { PowerShellAdditionalExePathSettings } from "./settings";
910

1011
// This uses require so we can rewire it in unit tests!
@@ -70,19 +71,9 @@ export function getPlatformDetails(): IPlatformDetails {
7071
export class PowerShellExeFinder {
7172
// This is required, since parseInt("7-preview") will return 7.
7273
private static IntRegex = /^\d+$/;
73-
7474
private static PwshMsixRegex = /^Microsoft.PowerShell_.*/;
75-
7675
private static PwshPreviewMsixRegex = /^Microsoft.PowerShellPreview_.*/;
77-
78-
// The platform details descriptor for the platform we're on
79-
private readonly platformDetails: IPlatformDetails;
80-
81-
// Additional configured PowerShells
82-
private readonly additionalPSExeSettings: PowerShellAdditionalExePathSettings;
83-
8476
private winPS: IPossiblePowerShellExe | undefined;
85-
8677
private alternateBitnessWinPS: IPossiblePowerShellExe | undefined;
8778

8879
/**
@@ -91,12 +82,11 @@ export class PowerShellExeFinder {
9182
* @param additionalPowerShellExes Additional PowerShell installations as configured in the settings.
9283
*/
9384
constructor(
94-
platformDetails?: IPlatformDetails,
95-
additionalPowerShellExes?: PowerShellAdditionalExePathSettings) {
96-
97-
this.platformDetails = platformDetails ?? getPlatformDetails();
98-
this.additionalPSExeSettings = additionalPowerShellExes ?? {};
99-
}
85+
// The platform details descriptor for the platform we're on
86+
private platformDetails: IPlatformDetails,
87+
// Additional configured PowerShells
88+
private additionalPowerShellExes: PowerShellAdditionalExePathSettings,
89+
private logger: Logger) { }
10090

10191
/**
10292
* Returns the first available PowerShell executable found in the search order.
@@ -159,6 +149,8 @@ export class PowerShellExeFinder {
159149
for (const additionalPwsh of this.enumerateAdditionalPowerShellInstallations()) {
160150
if (await additionalPwsh.exists()) {
161151
yield additionalPwsh;
152+
} else {
153+
void this.logger.writeAndShowWarning(`Additional PowerShell '${additionalPwsh.displayName}' not found at '${additionalPwsh.exePath}'!`);
162154
}
163155
}
164156
}
@@ -226,9 +218,9 @@ export class PowerShellExeFinder {
226218
* without checking for their existence.
227219
*/
228220
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
229-
for (const versionName in this.additionalPSExeSettings) {
230-
if (Object.prototype.hasOwnProperty.call(this.additionalPSExeSettings, versionName)) {
231-
const exePath = this.additionalPSExeSettings[versionName];
221+
for (const versionName in this.additionalPowerShellExes) {
222+
if (Object.prototype.hasOwnProperty.call(this.additionalPowerShellExes, versionName)) {
223+
const exePath = this.additionalPowerShellExes[versionName];
232224
if (exePath) {
233225
yield new PossiblePowerShellExe(exePath, versionName);
234226
}

src/session.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ export class SessionManager implements Middleware {
484484
private async findPowerShell(): Promise<IPowerShellExeDetails | undefined> {
485485
const powershellExeFinder = new PowerShellExeFinder(
486486
this.platformDetails,
487-
this.sessionSettings.powerShellAdditionalExePaths);
487+
this.sessionSettings.powerShellAdditionalExePaths,
488+
this.logger);
488489

489490
let foundPowerShell: IPowerShellExeDetails | undefined;
490491
try {
@@ -837,7 +838,8 @@ Type 'help' to get help.
837838
private async showSessionMenu() {
838839
const powershellExeFinder = new PowerShellExeFinder(
839840
this.platformDetails,
840-
this.sessionSettings.powerShellAdditionalExePaths);
841+
this.sessionSettings.powerShellAdditionalExePaths,
842+
this.logger);
841843
const availablePowerShellExes = await powershellExeFinder.getAllAvailablePowerShellInstallations();
842844

843845
let sessionText: string;

0 commit comments

Comments
 (0)