Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graduate PSReadLine feature and add UseLegacyReadLine #1076

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions module/PowerShellEditorServices/PowerShellEditorServices.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ function Start-EditorServicesHost {
[switch]
$EnableConsoleRepl,

[switch]
$UseLegacyReadLine,

[switch]
$DebugServiceOnly,

Expand All @@ -101,6 +104,7 @@ function Start-EditorServicesHost {
$hostDetails,
$BundledModulesPath,
$EnableConsoleRepl.IsPresent,
$UseLegacyReadLine.IsPresent,
$WaitForDebugger.IsPresent,
$AdditionalModules,
$FeatureFlags,
Expand Down
5 changes: 5 additions & 0 deletions module/PowerShellEditorServices/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ param(
[switch]
$EnableConsoleRepl,

[switch]
$UseLegacyReadLine,

[switch]
$DebugServiceOnly,

Expand Down Expand Up @@ -363,6 +366,7 @@ try {
-DebugServiceInNamedPipe $DebugServiceInPipeName `
-DebugServiceOutNamedPipe $DebugServiceOutPipeName `
-BundledModulesPath $BundledModulesPath `
-UseLegacyReadLine:$UseLegacyReadLine.IsPresent `
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent `
-DebugServiceOnly:$DebugServiceOnly.IsPresent `
-WaitForDebugger:$WaitForDebugger.IsPresent `
Expand All @@ -389,6 +393,7 @@ try {
-LanguageServiceNamedPipe $LanguageServicePipeName `
-DebugServiceNamedPipe $DebugServicePipeName `
-BundledModulesPath $BundledModulesPath `
-UseLegacyReadLine:$UseLegacyReadLine.IsPresent `
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent `
-DebugServiceOnly:$DebugServiceOnly.IsPresent `
-WaitForDebugger:$WaitForDebugger.IsPresent `
Expand Down
11 changes: 8 additions & 3 deletions src/PowerShellEditorServices/Hosting/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public class EditorServicesHost

private readonly bool _enableConsoleRepl;

private readonly bool _useLegacyReadLine;

private readonly HashSet<string> _featureFlags;

private readonly string[] _additionalModules;
Expand Down Expand Up @@ -113,13 +115,15 @@ public EditorServicesHost(
HostDetails hostDetails,
string bundledModulesPath,
bool enableConsoleRepl,
bool useLegacyReadLine,
bool waitForDebugger,
string[] additionalModules,
string[] featureFlags)
: this(
hostDetails,
bundledModulesPath,
enableConsoleRepl,
useLegacyReadLine,
waitForDebugger,
additionalModules,
featureFlags,
Expand All @@ -141,6 +145,7 @@ public EditorServicesHost(
HostDetails hostDetails,
string bundledModulesPath,
bool enableConsoleRepl,
bool useLegacyReadLine,
bool waitForDebugger,
string[] additionalModules,
string[] featureFlags,
Expand All @@ -151,12 +156,10 @@ public EditorServicesHost(

_hostDetails = hostDetails;

//this._hostDetails = hostDetails;
_enableConsoleRepl = enableConsoleRepl;
//this.bundledModulesPath = bundledModulesPath;
_useLegacyReadLine = useLegacyReadLine;
_additionalModules = additionalModules ?? Array.Empty<string>();
_featureFlags = new HashSet<string>(featureFlags ?? Array.Empty<string>());
//this.serverCompletedTask = new TaskCompletionSource<bool>();
_internalHost = internalHost;

#if DEBUG
Expand Down Expand Up @@ -247,6 +250,7 @@ public void StartLanguageService(
_factory,
LogLevel.Trace,
_enableConsoleRepl,
_useLegacyReadLine,
_featureFlags,
_hostDetails,
_additionalModules,
Expand Down Expand Up @@ -306,6 +310,7 @@ public void StartDebugService(
profilePaths,
_featureFlags,
_enableConsoleRepl,
_useLegacyReadLine,
_internalHost,
_hostDetails,
_additionalModules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal NamedPipePsesLanguageServer(
ILoggerFactory factory,
LogLevel minimumLogLevel,
bool enableConsoleRepl,
bool useLegacyReadLine,
HashSet<string> featureFlags,
HostDetails hostDetails,
string[] additionalModules,
Expand All @@ -44,6 +45,7 @@ internal NamedPipePsesLanguageServer(
factory,
minimumLogLevel,
enableConsoleRepl,
useLegacyReadLine,
featureFlags,
hostDetails,
additionalModules,
Expand Down
4 changes: 4 additions & 0 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal abstract class PsesLanguageServer

private readonly LogLevel _minimumLogLevel;
private readonly bool _enableConsoleRepl;
private readonly bool _useLegacyReadLine;
private readonly HashSet<string> _featureFlags;
private readonly HostDetails _hostDetails;
private readonly string[] _additionalModules;
Expand All @@ -38,6 +39,7 @@ internal PsesLanguageServer(
ILoggerFactory factory,
LogLevel minimumLogLevel,
bool enableConsoleRepl,
bool useLegacyReadLine,
HashSet<string> featureFlags,
HostDetails hostDetails,
string[] additionalModules,
Expand All @@ -47,6 +49,7 @@ internal PsesLanguageServer(
LoggerFactory = factory;
_minimumLogLevel = minimumLogLevel;
_enableConsoleRepl = enableConsoleRepl;
_useLegacyReadLine = useLegacyReadLine;
_featureFlags = featureFlags;
_hostDetails = hostDetails;
_additionalModules = additionalModules;
Expand All @@ -69,6 +72,7 @@ public async Task StartAsync()
_profilePaths,
_featureFlags,
_enableConsoleRepl,
_useLegacyReadLine,
_internalHost,
_hostDetails,
_additionalModules))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static IServiceCollection AddPsesLanguageServices (
ProfilePaths profilePaths,
HashSet<string> featureFlags,
bool enableConsoleRepl,
bool useLegacyReadLine,
PSHost internalHost,
HostDetails hostDetails,
string[] additionalModules)
Expand All @@ -35,6 +36,7 @@ public static IServiceCollection AddPsesLanguageServices (
profilePaths,
featureFlags,
enableConsoleRepl,
useLegacyReadLine,
internalHost,
hostDetails,
additionalModules))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ internal StdioPsesLanguageServer(
ProfilePaths profilePaths) : base(
factory,
minimumLogLevel,
// Stdio server can't support an integrated console so we pass in false.
false,
// Stdio server can't support an integrated console so we pass in false for
// enableConsoleRepl and useLegacyReadLine.
enableConsoleRepl: false,
useLegacyReadLine: false,
featureFlags,
hostDetails,
additionalModules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,26 @@ public static PowerShellContextService Create(
ProfilePaths profilePaths,
HashSet<string> featureFlags,
bool enableConsoleRepl,
bool useLegacyReadLine,
PSHost internalHost,
HostDetails hostDetails,
string[] additionalModules
)
{
var logger = factory.CreateLogger<PowerShellContextService>();

// 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
bool shouldUsePSReadLine = enableConsoleRepl && !useLegacyReadLine
&& (VersionUtils.IsWindows || !VersionUtils.IsPS6);

var powerShellContext = new PowerShellContextService(
logger,
languageServer,
featureFlags.Contains("PSReadLine") && enableConsoleRepl);
shouldUsePSReadLine);

EditorServicesPSHostUserInterface hostUserInterface =
enableConsoleRepl
Expand Down
5 changes: 5 additions & 0 deletions src/PowerShellEditorServices/Utility/VersionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ internal static class VersionUtils
/// True if we are running in PowerShell 7, false otherwise.
/// </summary>
public static bool IsPS7 { get; } = PSVersion.Major == 7;

/// <summary>
/// True if we are running in on Windows, false otherwise.
/// </summary>
public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}

internal static class PowerShellReflectionUtils
Expand Down