Skip to content

Commit 380302c

Browse files
committed
Fix additional PowerShell warning (take two)
Since Show Session Menu always fully enumerates the iterator we needed to move the existence check into the generator. Fortunately the 'exists' method was already idempotent. I'd like this to be cleaner, but at least the tests now make sense (and required a stub fix).
1 parent 7a42c84 commit 380302c

File tree

2 files changed

+82
-159
lines changed

2 files changed

+82
-159
lines changed

src/platform.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class PowerShellExeFinder {
148148

149149
// Also show any additionally configured PowerShells
150150
// These may be duplicates of the default installations, but given a different name.
151-
for (const additionalPwsh of this.enumerateAdditionalPowerShellInstallations()) {
151+
for await (const additionalPwsh of this.enumerateAdditionalPowerShellInstallations()) {
152152
if (await additionalPwsh.exists()) {
153153
yield additionalPwsh;
154154
} else if (!additionalPwsh.suppressWarning) {
@@ -230,7 +230,7 @@ export class PowerShellExeFinder {
230230
* Iterates through the configured additional PowerShell executable locations,
231231
* without checking for their existence.
232232
*/
233-
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
233+
private async *enumerateAdditionalPowerShellInstallations(): AsyncIterable<IPossiblePowerShellExe> {
234234
for (const versionName in this.additionalPowerShellExes) {
235235
if (Object.prototype.hasOwnProperty.call(this.additionalPowerShellExes, versionName)) {
236236
let exePath: string | undefined = utils.stripQuotePair(this.additionalPowerShellExes[versionName]);
@@ -245,24 +245,44 @@ export class PowerShellExeFinder {
245245

246246
// Always search for what the user gave us first, but with the warning
247247
// suppressed so we can display it after all possibilities are exhausted
248-
yield new PossiblePowerShellExe(exePath, ...args);
248+
let pwsh = new PossiblePowerShellExe(exePath, ...args);
249+
if (await pwsh.exists()) {
250+
yield pwsh;
251+
continue;
252+
}
249253

250254
// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
251255
if (this.platformDetails.operatingSystem === OperatingSystem.Windows) {
252256
// Handle Windows where '.exe' and 'powershell' are things
253257
if (!exePath.endsWith("pwsh.exe") && !exePath.endsWith("powershell.exe")) {
254258
if (exePath.endsWith("pwsh") || exePath.endsWith("powershell")) {
255259
// Add extension if that was missing
256-
yield new PossiblePowerShellExe(exePath + ".exe", ...args);
260+
pwsh = new PossiblePowerShellExe(exePath + ".exe", ...args);
261+
if (await pwsh.exists()) {
262+
yield pwsh;
263+
continue;
264+
}
257265
}
258266
// Also add full exe names (this isn't an else just in case
259267
// the folder was named "pwsh" or "powershell")
260-
yield new PossiblePowerShellExe(path.join(exePath, "pwsh.exe"), ...args);
261-
yield new PossiblePowerShellExe(path.join(exePath, "powershell.exe"), ...args);
268+
pwsh = new PossiblePowerShellExe(path.join(exePath, "pwsh.exe"), ...args);
269+
if (await pwsh.exists()) {
270+
yield pwsh;
271+
continue;
272+
}
273+
pwsh = new PossiblePowerShellExe(path.join(exePath, "powershell.exe"), ...args);
274+
if (await pwsh.exists()) {
275+
yield pwsh;
276+
continue;
277+
}
262278
}
263279
} else if (!exePath.endsWith("pwsh")) {
264280
// Always just 'pwsh' on non-Windows
265-
yield new PossiblePowerShellExe(path.join(exePath, "pwsh"), ...args);
281+
pwsh = new PossiblePowerShellExe(path.join(exePath, "pwsh"), ...args);
282+
if (await pwsh.exists()) {
283+
yield pwsh;
284+
continue;
285+
}
266286
}
267287

268288
// If we're still being iterated over, no permutation of the given path existed so yield an object with the warning unsuppressed

0 commit comments

Comments
 (0)