Skip to content

Commit 140c976

Browse files
Move PSRL decision option to be in Hosting (#1200)
* Move PSRL decision option to be in Hosting * use if defs
1 parent 3fcd0c6 commit 140c976

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
using SMA = System.Management.Automation;
1414
using Microsoft.PowerShell.EditorServices.Hosting;
1515
using System.Globalization;
16+
using System.Collections;
17+
18+
// TODO: Remove this when we drop support for PS6.
19+
#if CoreCLR
20+
using System.Runtime.InteropServices;
21+
#endif
1622

1723
#if DEBUG
1824
using System.Diagnostics;
@@ -30,6 +36,14 @@ namespace Microsoft.PowerShell.EditorServices.Commands
3036
[Cmdlet(VerbsLifecycle.Start, "EditorServices", DefaultParameterSetName = "NamedPipe")]
3137
public sealed class StartEditorServicesCommand : PSCmdlet
3238
{
39+
// TODO: Remove this when we drop support for PS6.
40+
private static bool s_isWindows =
41+
#if CoreCLR
42+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
43+
#else
44+
true;
45+
#endif
46+
3347
private readonly List<IDisposable> _disposableResources;
3448

3549
private readonly List<IDisposable> _loggerUnsubscribers;
@@ -376,6 +390,11 @@ private string GetProfilePathFromProfileObject(PSObject profileObject, ProfileUs
376390
$"{HostProfileId}_profile.ps1");
377391
}
378392

393+
// We should only use PSReadLine if we specificied that we want a console repl
394+
// and we have not explicitly said to use the legacy ReadLine.
395+
// We also want it if we are either:
396+
// * On Windows on any version OR
397+
// * On Linux or macOS on any version greater than or equal to 7
379398
private ConsoleReplKind GetReplKind()
380399
{
381400
_logger.Log(PsesLogLevel.Diagnostic, "Determining REPL kind");
@@ -386,7 +405,12 @@ private ConsoleReplKind GetReplKind()
386405
return ConsoleReplKind.None;
387406
}
388407

389-
if (UseLegacyReadLine)
408+
// TODO: Remove this when we drop support for PS6.
409+
var psVersionTable = (Hashtable) this.SessionState.PSVariable.GetValue("PSVersionTable");
410+
dynamic version = psVersionTable["PSVersion"];
411+
var majorVersion = (int) version.Major;
412+
413+
if (UseLegacyReadLine || (!s_isWindows && majorVersion == 6))
390414
{
391415
_logger.Log(PsesLogLevel.Diagnostic, "REPL configured as Legacy");
392416
return ConsoleReplKind.LegacyReadLine;

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,8 @@ public static PowerShellContextService Create(
183183

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

186-
// We should only use PSReadLine if we specificied that we want a console repl
187-
// and we have not explicitly said to use the legacy ReadLine.
188-
// We also want it if we are either:
189-
// * On Windows on any version OR
190-
// * On Linux or macOS on any version greater than or equal to 7
191186
bool shouldUsePSReadLine = hostStartupInfo.ConsoleReplEnabled
192-
&& !hostStartupInfo.UsesLegacyReadLine
193-
&& (VersionUtils.IsWindows || !VersionUtils.IsPS6);
187+
&& !hostStartupInfo.UsesLegacyReadLine;
194188

195189
var powerShellContext = new PowerShellContextService(
196190
logger,

0 commit comments

Comments
 (0)