Skip to content

Commit

Permalink
Move PSRL decision option to be in Hosting (#1200)
Browse files Browse the repository at this point in the history
* Move PSRL decision option to be in Hosting

* use if defs
  • Loading branch information
TylerLeonhardt authored Feb 18, 2020
1 parent 3fcd0c6 commit 140c976
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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

0 comments on commit 140c976

Please sign in to comment.