From 31030de2dcbb4e25db771adac7096203fae25218 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 18 Feb 2020 13:57:52 -0800 Subject: [PATCH 1/2] Move PSRL decision option to be in Hosting --- .../Commands/StartEditorServicesCommand.cs | 17 ++++++++++++++++- .../PowerShellContextService.cs | 8 +------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index f12bbc905..72af6de12 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -13,6 +13,8 @@ using SMA = System.Management.Automation; using Microsoft.PowerShell.EditorServices.Hosting; using System.Globalization; +using System.Runtime.InteropServices; +using System.Collections; #if DEBUG using System.Diagnostics; @@ -30,6 +32,9 @@ namespace Microsoft.PowerShell.EditorServices.Commands [Cmdlet(VerbsLifecycle.Start, "EditorServices", DefaultParameterSetName = "NamedPipe")] public sealed class StartEditorServicesCommand : PSCmdlet { + // TODO: Remove this when we drop support for PS6 + private static bool _isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + private readonly List _disposableResources; private readonly List _loggerUnsubscribers; @@ -376,6 +381,11 @@ private string GetProfilePathFromProfileObject(PSObject profileObject, ProfileUs $"{HostProfileId}_profile.ps1"); } + // We should only use PSReadLine if we specificied that we want a console repl + // and we have not explicitly said to use the legacy ReadLine. + // We also want it if we are either: + // * On Windows on any version OR + // * On Linux or macOS on any version greater than or equal to 7 private ConsoleReplKind GetReplKind() { _logger.Log(PsesLogLevel.Diagnostic, "Determining REPL kind"); @@ -386,7 +396,12 @@ private ConsoleReplKind GetReplKind() return ConsoleReplKind.None; } - if (UseLegacyReadLine) + // TODO: Remove this when we drop PS6 support. + var psVersionTable = (Hashtable) this.SessionState.PSVariable.GetValue("PSVersionTable"); + dynamic version = psVersionTable["PSVersion"]; + var majorVersion = (int) version.Major; + + if (UseLegacyReadLine || (!_isWindows && majorVersion == 6)) { _logger.Log(PsesLogLevel.Diagnostic, "REPL configured as Legacy"); return ConsoleReplKind.LegacyReadLine; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs index efe33f120..b75a588ff 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs @@ -183,14 +183,8 @@ public static PowerShellContextService Create( var logger = factory.CreateLogger(); - // We should only use PSReadLine if we specificied that we want a console repl - // and we have not explicitly said to use the legacy ReadLine. - // We also want it if we are either: - // * On Windows on any version OR - // * On Linux or macOS on any version greater than or equal to 7 bool shouldUsePSReadLine = hostStartupInfo.ConsoleReplEnabled - && !hostStartupInfo.UsesLegacyReadLine - && (VersionUtils.IsWindows || !VersionUtils.IsPS6); + && !hostStartupInfo.UsesLegacyReadLine; var powerShellContext = new PowerShellContextService( logger, From c4a0402ae77ea91705f2c89fc4b3aa69ff135496 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 18 Feb 2020 15:07:04 -0800 Subject: [PATCH 2/2] use if defs --- .../Commands/StartEditorServicesCommand.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 72af6de12..e27de4c42 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -13,9 +13,13 @@ using SMA = System.Management.Automation; using Microsoft.PowerShell.EditorServices.Hosting; using System.Globalization; -using System.Runtime.InteropServices; using System.Collections; +// TODO: Remove this when we drop support for PS6. +#if CoreCLR +using System.Runtime.InteropServices; +#endif + #if DEBUG using System.Diagnostics; using System.Threading; @@ -32,8 +36,13 @@ namespace Microsoft.PowerShell.EditorServices.Commands [Cmdlet(VerbsLifecycle.Start, "EditorServices", DefaultParameterSetName = "NamedPipe")] public sealed class StartEditorServicesCommand : PSCmdlet { - // TODO: Remove this when we drop support for PS6 - private static bool _isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + // TODO: Remove this when we drop support for PS6. + private static bool s_isWindows = +#if CoreCLR + RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else + true; +#endif private readonly List _disposableResources; @@ -396,12 +405,12 @@ private ConsoleReplKind GetReplKind() return ConsoleReplKind.None; } - // TODO: Remove this when we drop PS6 support. + // TODO: Remove this when we drop support for PS6. var psVersionTable = (Hashtable) this.SessionState.PSVariable.GetValue("PSVersionTable"); dynamic version = psVersionTable["PSVersion"]; var majorVersion = (int) version.Major; - if (UseLegacyReadLine || (!_isWindows && majorVersion == 6)) + if (UseLegacyReadLine || (!s_isWindows && majorVersion == 6)) { _logger.Log(PsesLogLevel.Diagnostic, "REPL configured as Legacy"); return ConsoleReplKind.LegacyReadLine;