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

Move PSRL decision option to be in Hosting #1200

Merged
merged 2 commits into from
Feb 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
using SMA = System.Management.Automation;
using Microsoft.PowerShell.EditorServices.Hosting;
using System.Globalization;
using System.Collections;

// TODO: Remove this when we drop support for PS6.
#if CoreCLR
using System.Runtime.InteropServices;
#endif

#if DEBUG
using System.Diagnostics;
Expand All @@ -30,6 +36,14 @@ 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 s_isWindows =
#if CoreCLR
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
true;
#endif

private readonly List<IDisposable> _disposableResources;

private readonly List<IDisposable> _loggerUnsubscribers;
Expand Down Expand Up @@ -376,6 +390,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");
Expand All @@ -386,7 +405,12 @@ private ConsoleReplKind GetReplKind()
return ConsoleReplKind.None;
}

if (UseLegacyReadLine)
// 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 || (!s_isWindows && majorVersion == 6))
{
_logger.Log(PsesLogLevel.Diagnostic, "REPL configured as Legacy");
return ConsoleReplKind.LegacyReadLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,8 @@ public static PowerShellContextService Create(

var logger = factory.CreateLogger<PowerShellContextService>();

// 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,
Expand Down