From 940945373ace7d21e381d9d710869068a6bef884 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 30 Oct 2019 10:27:35 -0700 Subject: [PATCH 1/2] graduate PSReadLine feature --- .../PowerShellEditorServices.psm1 | 4 ++++ .../Start-EditorServices.ps1 | 5 +++++ .../Hosting/EditorServicesHost.cs | 11 ++++++++--- .../Server/NamedPipePsesLanguageServer.cs | 2 ++ .../Server/PsesLanguageServer.cs | 4 ++++ .../Server/PsesServiceCollectionExtensions.cs | 2 ++ .../Server/StdioPsesLanguageServer.cs | 4 +++- .../PowerShellContext/PowerShellContextService.cs | 13 ++++++++++--- .../Utility/VersionUtils.cs | 5 +++++ 9 files changed, 43 insertions(+), 7 deletions(-) diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 index 5861b9420..770e516f8 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -75,6 +75,9 @@ function Start-EditorServicesHost { [switch] $EnableConsoleRepl, + [switch] + $UseLegacyReadLine, + [switch] $DebugServiceOnly, @@ -101,6 +104,7 @@ function Start-EditorServicesHost { $hostDetails, $BundledModulesPath, $EnableConsoleRepl.IsPresent, + $UseLegacyReadLine.IsPresent, $WaitForDebugger.IsPresent, $AdditionalModules, $FeatureFlags, diff --git a/module/PowerShellEditorServices/Start-EditorServices.ps1 b/module/PowerShellEditorServices/Start-EditorServices.ps1 index acb221f94..5f828a905 100644 --- a/module/PowerShellEditorServices/Start-EditorServices.ps1 +++ b/module/PowerShellEditorServices/Start-EditorServices.ps1 @@ -57,6 +57,9 @@ param( [switch] $EnableConsoleRepl, + [switch] + $UseLegacyReadLine, + [switch] $DebugServiceOnly, @@ -363,6 +366,7 @@ try { -DebugServiceInNamedPipe $DebugServiceInPipeName ` -DebugServiceOutNamedPipe $DebugServiceOutPipeName ` -BundledModulesPath $BundledModulesPath ` + -UseLegacyReadLine:$UseLegacyReadLine.IsPresent ` -EnableConsoleRepl:$EnableConsoleRepl.IsPresent ` -DebugServiceOnly:$DebugServiceOnly.IsPresent ` -WaitForDebugger:$WaitForDebugger.IsPresent ` @@ -389,6 +393,7 @@ try { -LanguageServiceNamedPipe $LanguageServicePipeName ` -DebugServiceNamedPipe $DebugServicePipeName ` -BundledModulesPath $BundledModulesPath ` + -UseLegacyReadLine:$UseLegacyReadLine.IsPresent ` -EnableConsoleRepl:$EnableConsoleRepl.IsPresent ` -DebugServiceOnly:$DebugServiceOnly.IsPresent ` -WaitForDebugger:$WaitForDebugger.IsPresent ` diff --git a/src/PowerShellEditorServices/Hosting/EditorServicesHost.cs b/src/PowerShellEditorServices/Hosting/EditorServicesHost.cs index 68c004c0c..eed6555fa 100644 --- a/src/PowerShellEditorServices/Hosting/EditorServicesHost.cs +++ b/src/PowerShellEditorServices/Hosting/EditorServicesHost.cs @@ -79,6 +79,8 @@ public class EditorServicesHost private readonly bool _enableConsoleRepl; + private readonly bool _useLegacyReadLine; + private readonly HashSet _featureFlags; private readonly string[] _additionalModules; @@ -113,6 +115,7 @@ public EditorServicesHost( HostDetails hostDetails, string bundledModulesPath, bool enableConsoleRepl, + bool useLegacyReadLine, bool waitForDebugger, string[] additionalModules, string[] featureFlags) @@ -120,6 +123,7 @@ public EditorServicesHost( hostDetails, bundledModulesPath, enableConsoleRepl, + useLegacyReadLine, waitForDebugger, additionalModules, featureFlags, @@ -141,6 +145,7 @@ public EditorServicesHost( HostDetails hostDetails, string bundledModulesPath, bool enableConsoleRepl, + bool useLegacyReadLine, bool waitForDebugger, string[] additionalModules, string[] featureFlags, @@ -151,12 +156,10 @@ public EditorServicesHost( _hostDetails = hostDetails; - //this._hostDetails = hostDetails; _enableConsoleRepl = enableConsoleRepl; - //this.bundledModulesPath = bundledModulesPath; + _useLegacyReadLine = useLegacyReadLine; _additionalModules = additionalModules ?? Array.Empty(); _featureFlags = new HashSet(featureFlags ?? Array.Empty()); - //this.serverCompletedTask = new TaskCompletionSource(); _internalHost = internalHost; #if DEBUG @@ -247,6 +250,7 @@ public void StartLanguageService( _factory, LogLevel.Trace, _enableConsoleRepl, + _useLegacyReadLine, _featureFlags, _hostDetails, _additionalModules, @@ -306,6 +310,7 @@ public void StartDebugService( profilePaths, _featureFlags, _enableConsoleRepl, + _useLegacyReadLine, _internalHost, _hostDetails, _additionalModules) diff --git a/src/PowerShellEditorServices/Server/NamedPipePsesLanguageServer.cs b/src/PowerShellEditorServices/Server/NamedPipePsesLanguageServer.cs index 864373a30..16f9bc749 100644 --- a/src/PowerShellEditorServices/Server/NamedPipePsesLanguageServer.cs +++ b/src/PowerShellEditorServices/Server/NamedPipePsesLanguageServer.cs @@ -34,6 +34,7 @@ internal NamedPipePsesLanguageServer( ILoggerFactory factory, LogLevel minimumLogLevel, bool enableConsoleRepl, + bool useLegacyReadLine, HashSet featureFlags, HostDetails hostDetails, string[] additionalModules, @@ -44,6 +45,7 @@ internal NamedPipePsesLanguageServer( factory, minimumLogLevel, enableConsoleRepl, + useLegacyReadLine, featureFlags, hostDetails, additionalModules, diff --git a/src/PowerShellEditorServices/Server/PsesLanguageServer.cs b/src/PowerShellEditorServices/Server/PsesLanguageServer.cs index ed62b206d..be64e2d49 100644 --- a/src/PowerShellEditorServices/Server/PsesLanguageServer.cs +++ b/src/PowerShellEditorServices/Server/PsesLanguageServer.cs @@ -27,6 +27,7 @@ internal abstract class PsesLanguageServer private readonly LogLevel _minimumLogLevel; private readonly bool _enableConsoleRepl; + private readonly bool _useLegacyReadLine; private readonly HashSet _featureFlags; private readonly HostDetails _hostDetails; private readonly string[] _additionalModules; @@ -38,6 +39,7 @@ internal PsesLanguageServer( ILoggerFactory factory, LogLevel minimumLogLevel, bool enableConsoleRepl, + bool useLegacyReadLine, HashSet featureFlags, HostDetails hostDetails, string[] additionalModules, @@ -47,6 +49,7 @@ internal PsesLanguageServer( LoggerFactory = factory; _minimumLogLevel = minimumLogLevel; _enableConsoleRepl = enableConsoleRepl; + _useLegacyReadLine = useLegacyReadLine; _featureFlags = featureFlags; _hostDetails = hostDetails; _additionalModules = additionalModules; @@ -69,6 +72,7 @@ public async Task StartAsync() _profilePaths, _featureFlags, _enableConsoleRepl, + _useLegacyReadLine, _internalHost, _hostDetails, _additionalModules)) diff --git a/src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs b/src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs index cd66847b0..074178567 100644 --- a/src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs +++ b/src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs @@ -20,6 +20,7 @@ public static IServiceCollection AddPsesLanguageServices ( ProfilePaths profilePaths, HashSet featureFlags, bool enableConsoleRepl, + bool useLegacyReadLine, PSHost internalHost, HostDetails hostDetails, string[] additionalModules) @@ -35,6 +36,7 @@ public static IServiceCollection AddPsesLanguageServices ( profilePaths, featureFlags, enableConsoleRepl, + useLegacyReadLine, internalHost, hostDetails, additionalModules)) diff --git a/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs b/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs index a2c699b5e..563a74879 100644 --- a/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs +++ b/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs @@ -23,7 +23,9 @@ internal StdioPsesLanguageServer( ProfilePaths profilePaths) : base( factory, minimumLogLevel, - // Stdio server can't support an integrated console so we pass in false. + // Stdio server can't support an integrated console so we pass in false for + // enableConsoleRepl and useLegacyReadLine. + false, false, featureFlags, hostDetails, diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs index a1f54a0de..872b18fb6 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs @@ -171,6 +171,7 @@ public static PowerShellContextService Create( ProfilePaths profilePaths, HashSet featureFlags, bool enableConsoleRepl, + bool useLegacyReadLine, PSHost internalHost, HostDetails hostDetails, string[] additionalModules @@ -178,12 +179,18 @@ string[] additionalModules { var logger = factory.CreateLogger(); - // PSReadLine can only be used when -EnableConsoleRepl is specified otherwise - // issues arise when redirecting stdio. + // 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 + var shouldUsePSReadLine = enableConsoleRepl && !useLegacyReadLine + && (VersionUtils.IsWindows || (!VersionUtils.IsWindows && !VersionUtils.IsPS6)); + var powerShellContext = new PowerShellContextService( logger, languageServer, - featureFlags.Contains("PSReadLine") && enableConsoleRepl); + shouldUsePSReadLine); EditorServicesPSHostUserInterface hostUserInterface = enableConsoleRepl diff --git a/src/PowerShellEditorServices/Utility/VersionUtils.cs b/src/PowerShellEditorServices/Utility/VersionUtils.cs index e2f2be54d..5493467aa 100644 --- a/src/PowerShellEditorServices/Utility/VersionUtils.cs +++ b/src/PowerShellEditorServices/Utility/VersionUtils.cs @@ -48,6 +48,11 @@ internal static class VersionUtils /// True if we are running in PowerShell 7, false otherwise. /// public static bool IsPS7 { get; } = PSVersion.Major == 7; + + /// + /// True if we are running in on Windows, false otherwise. + /// + public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } internal static class PowerShellReflectionUtils From 17860b37afedd7998df55d0681c5f2a8710e5fa9 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 30 Oct 2019 15:36:36 -0700 Subject: [PATCH 2/2] Rob's feedback --- .../Server/StdioPsesLanguageServer.cs | 4 ++-- .../Services/PowerShellContext/PowerShellContextService.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs b/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs index 563a74879..741404cac 100644 --- a/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs +++ b/src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs @@ -25,8 +25,8 @@ internal StdioPsesLanguageServer( minimumLogLevel, // Stdio server can't support an integrated console so we pass in false for // enableConsoleRepl and useLegacyReadLine. - false, - false, + enableConsoleRepl: false, + useLegacyReadLine: false, featureFlags, hostDetails, additionalModules, diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs index 872b18fb6..3f1a03c32 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs @@ -184,8 +184,8 @@ string[] additionalModules // 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 - var shouldUsePSReadLine = enableConsoleRepl && !useLegacyReadLine - && (VersionUtils.IsWindows || (!VersionUtils.IsWindows && !VersionUtils.IsPS6)); + bool shouldUsePSReadLine = enableConsoleRepl && !useLegacyReadLine + && (VersionUtils.IsWindows || !VersionUtils.IsPS6); var powerShellContext = new PowerShellContextService( logger,