diff --git a/src/features/ShowHelp.ts b/src/features/ShowHelp.ts index 2db801bf42..0ea08e3b28 100644 --- a/src/features/ShowHelp.ts +++ b/src/features/ShowHelp.ts @@ -18,7 +18,7 @@ export class ShowHelpFeature extends LanguageClientConsumer { constructor() { super(); this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", async (item?) => { - if (!item || !item.Name) { + if (!item?.Name) { const editor = vscode.window.activeTextEditor; if (editor === undefined) { diff --git a/src/platform.ts b/src/platform.ts index b0d2c1daa8..a316e5e396 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -211,6 +211,9 @@ export class PowerShellExeFinder { break; } + + // Look for PSCore daily + yield this.findPSCoreDaily(); } /** @@ -260,6 +263,42 @@ export class PowerShellExeFinder { } } + /** + * If the daily was installed via 'https://aka.ms/install-powershell.ps1', then + * this is the default installation location: + * + * if ($IsWinEnv) { + * $Destination = "$env:LOCALAPPDATA\Microsoft\powershell" + * } else { + * $Destination = "~/.powershell" + * } + * + * if ($Daily) { + * $Destination = "${Destination}-daily" + * } + */ + private findPSCoreDaily(): IPossiblePowerShellExe | undefined { + switch (this.platformDetails.operatingSystem) { + case OperatingSystem.Linux: + case OperatingSystem.MacOS: { + const exePath = path.join(os.homedir(), ".powershell-daily", "pwsh"); + return new PossiblePowerShellExe(exePath, "PowerShell Daily"); + } + + case OperatingSystem.Windows: { + // We can't proceed if there's no LOCALAPPDATA path + if (!process.env.LOCALAPPDATA) { + return undefined; + } + const exePath = path.join(process.env.LOCALAPPDATA, "Microsoft", "powershell-daily", "pwsh.exe"); + return new PossiblePowerShellExe(exePath, "PowerShell Daily"); + } + + case OperatingSystem.Unknown: + return undefined; + } + } + private findPSCoreDotnetGlobalTool(): IPossiblePowerShellExe { const exeName: string = this.platformDetails.operatingSystem === OperatingSystem.Windows ? "pwsh.exe" diff --git a/test/core/platform.test.ts b/test/core/platform.test.ts index 6058ccf388..2dcd7541ec 100644 --- a/test/core/platform.test.ts +++ b/test/core/platform.test.ts @@ -4,6 +4,7 @@ import * as assert from "assert"; import mockFS = require("mock-fs"); import FileSystem = require("mock-fs/lib/filesystem"); +import * as os from "os"; import * as path from "path"; import rewire = require("rewire"); import * as sinon from "sinon"; @@ -61,14 +62,13 @@ interface ITestPlatformSuccessCase extends ITestPlatform { // Platform configurations where we expect to find a set of PowerShells let successTestCases: ITestPlatformSuccessCase[]; -let msixAppDir: string; -let pwshMsixPath: string; -let pwshPreviewMsixPath: string; if (process.platform === "win32") { - msixAppDir = path.join(process.env.LOCALAPPDATA!, "Microsoft", "WindowsApps"); - pwshMsixPath = path.join(msixAppDir, "Microsoft.PowerShell_8wekyb3d8bbwe", "pwsh.exe"); - pwshPreviewMsixPath = path.join(msixAppDir, "Microsoft.PowerShellPreview_8wekyb3d8bbwe", "pwsh.exe"); + const msixAppDir = path.join(process.env.LOCALAPPDATA!, "Microsoft", "WindowsApps"); + const pwshMsixPath = path.join(msixAppDir, "Microsoft.PowerShell_8wekyb3d8bbwe", "pwsh.exe"); + const pwshPreviewMsixPath = path.join(msixAppDir, "Microsoft.PowerShellPreview_8wekyb3d8bbwe", "pwsh.exe"); + const pwshDailyDir = path.join(process.env.LOCALAPPDATA!, "Microsoft", "powershell-daily"); + const pwshDailyPath = path.join(pwshDailyDir, "pwsh.exe"); successTestCases = [ { @@ -124,6 +124,11 @@ if (process.platform === "win32") { displayName: "Windows PowerShell (x86)", supportsProperArguments: true }, + { + exePath: pwshDailyPath, + displayName: "PowerShell Daily", + supportsProperArguments: true + } ], filesystem: { "C:\\Program Files\\PowerShell": { @@ -156,6 +161,9 @@ if (process.platform === "win32") { "C:\\WINDOWS\\SysWOW64\\WindowsPowerShell\\v1.0": { "powershell.exe": "", }, + [pwshDailyDir]: { + "pwsh.exe": "", + } }, }, { @@ -436,6 +444,7 @@ if (process.platform === "win32") { }, ]; } else { + const pwshDailyDir = path.join(os.homedir(), ".powershell-daily"); successTestCases = [ { name: "Linux (all installations)", @@ -466,6 +475,11 @@ if (process.platform === "win32") { displayName: "PowerShell Preview Snap", supportsProperArguments: true }, + { + exePath: path.join(pwshDailyDir, "pwsh"), + displayName: "PowerShell Daily", + supportsProperArguments: true + } ], filesystem: { "/usr/bin": { @@ -476,6 +490,9 @@ if (process.platform === "win32") { "pwsh": "", "pwsh-preview": "", }, + [pwshDailyDir]: { + "pwsh": "" + } }, }, { @@ -497,12 +514,20 @@ if (process.platform === "win32") { displayName: "PowerShell Preview", supportsProperArguments: true }, + { + exePath: path.join(pwshDailyDir, "pwsh"), + displayName: "PowerShell Daily", + supportsProperArguments: true + } ], filesystem: { "/usr/local/bin": { "pwsh": "", "pwsh-preview": "", }, + [pwshDailyDir]: { + "pwsh": "" + } }, }, {