13
13
using SMA = System . Management . Automation ;
14
14
using Microsoft . PowerShell . EditorServices . Hosting ;
15
15
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
16
22
17
23
#if DEBUG
18
24
using System . Diagnostics ;
@@ -30,6 +36,14 @@ namespace Microsoft.PowerShell.EditorServices.Commands
30
36
[ Cmdlet ( VerbsLifecycle . Start , "EditorServices" , DefaultParameterSetName = "NamedPipe" ) ]
31
37
public sealed class StartEditorServicesCommand : PSCmdlet
32
38
{
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
+
33
47
private readonly List < IDisposable > _disposableResources ;
34
48
35
49
private readonly List < IDisposable > _loggerUnsubscribers ;
@@ -376,6 +390,11 @@ private string GetProfilePathFromProfileObject(PSObject profileObject, ProfileUs
376
390
$ "{ HostProfileId } _profile.ps1") ;
377
391
}
378
392
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
379
398
private ConsoleReplKind GetReplKind ( )
380
399
{
381
400
_logger . Log ( PsesLogLevel . Diagnostic , "Determining REPL kind" ) ;
@@ -386,7 +405,12 @@ private ConsoleReplKind GetReplKind()
386
405
return ConsoleReplKind . None ;
387
406
}
388
407
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 ) )
390
414
{
391
415
_logger . Log ( PsesLogLevel . Diagnostic , "REPL configured as Legacy" ) ;
392
416
return ConsoleReplKind . LegacyReadLine ;
0 commit comments