Skip to content

Commit 259fe9a

Browse files
TylerLeonhardtrjmholt
authored andcommitted
Graduate PSReadLine feature and add UseLegacyReadLine (#1076)
1 parent 75049b7 commit 259fe9a

File tree

9 files changed

+44
-8
lines changed

9 files changed

+44
-8
lines changed

module/PowerShellEditorServices/PowerShellEditorServices.psm1

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ function Start-EditorServicesHost {
7575
[switch]
7676
$EnableConsoleRepl,
7777

78+
[switch]
79+
$UseLegacyReadLine,
80+
7881
[switch]
7982
$DebugServiceOnly,
8083

@@ -101,6 +104,7 @@ function Start-EditorServicesHost {
101104
$hostDetails,
102105
$BundledModulesPath,
103106
$EnableConsoleRepl.IsPresent,
107+
$UseLegacyReadLine.IsPresent,
104108
$WaitForDebugger.IsPresent,
105109
$AdditionalModules,
106110
$FeatureFlags,

module/PowerShellEditorServices/Start-EditorServices.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ param(
5757
[switch]
5858
$EnableConsoleRepl,
5959

60+
[switch]
61+
$UseLegacyReadLine,
62+
6063
[switch]
6164
$DebugServiceOnly,
6265

@@ -363,6 +366,7 @@ try {
363366
-DebugServiceInNamedPipe $DebugServiceInPipeName `
364367
-DebugServiceOutNamedPipe $DebugServiceOutPipeName `
365368
-BundledModulesPath $BundledModulesPath `
369+
-UseLegacyReadLine:$UseLegacyReadLine.IsPresent `
366370
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent `
367371
-DebugServiceOnly:$DebugServiceOnly.IsPresent `
368372
-WaitForDebugger:$WaitForDebugger.IsPresent `
@@ -389,6 +393,7 @@ try {
389393
-LanguageServiceNamedPipe $LanguageServicePipeName `
390394
-DebugServiceNamedPipe $DebugServicePipeName `
391395
-BundledModulesPath $BundledModulesPath `
396+
-UseLegacyReadLine:$UseLegacyReadLine.IsPresent `
392397
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent `
393398
-DebugServiceOnly:$DebugServiceOnly.IsPresent `
394399
-WaitForDebugger:$WaitForDebugger.IsPresent `

src/PowerShellEditorServices/Hosting/EditorServicesHost.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public class EditorServicesHost
7979

8080
private readonly bool _enableConsoleRepl;
8181

82+
private readonly bool _useLegacyReadLine;
83+
8284
private readonly HashSet<string> _featureFlags;
8385

8486
private readonly string[] _additionalModules;
@@ -113,13 +115,15 @@ public EditorServicesHost(
113115
HostDetails hostDetails,
114116
string bundledModulesPath,
115117
bool enableConsoleRepl,
118+
bool useLegacyReadLine,
116119
bool waitForDebugger,
117120
string[] additionalModules,
118121
string[] featureFlags)
119122
: this(
120123
hostDetails,
121124
bundledModulesPath,
122125
enableConsoleRepl,
126+
useLegacyReadLine,
123127
waitForDebugger,
124128
additionalModules,
125129
featureFlags,
@@ -141,6 +145,7 @@ public EditorServicesHost(
141145
HostDetails hostDetails,
142146
string bundledModulesPath,
143147
bool enableConsoleRepl,
148+
bool useLegacyReadLine,
144149
bool waitForDebugger,
145150
string[] additionalModules,
146151
string[] featureFlags,
@@ -151,12 +156,10 @@ public EditorServicesHost(
151156

152157
_hostDetails = hostDetails;
153158

154-
//this._hostDetails = hostDetails;
155159
_enableConsoleRepl = enableConsoleRepl;
156-
//this.bundledModulesPath = bundledModulesPath;
160+
_useLegacyReadLine = useLegacyReadLine;
157161
_additionalModules = additionalModules ?? Array.Empty<string>();
158162
_featureFlags = new HashSet<string>(featureFlags ?? Array.Empty<string>());
159-
//this.serverCompletedTask = new TaskCompletionSource<bool>();
160163
_internalHost = internalHost;
161164

162165
#if DEBUG
@@ -247,6 +250,7 @@ public void StartLanguageService(
247250
_factory,
248251
LogLevel.Trace,
249252
_enableConsoleRepl,
253+
_useLegacyReadLine,
250254
_featureFlags,
251255
_hostDetails,
252256
_additionalModules,
@@ -306,6 +310,7 @@ public void StartDebugService(
306310
profilePaths,
307311
_featureFlags,
308312
_enableConsoleRepl,
313+
_useLegacyReadLine,
309314
_internalHost,
310315
_hostDetails,
311316
_additionalModules)

src/PowerShellEditorServices/Server/NamedPipePsesLanguageServer.cs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ internal NamedPipePsesLanguageServer(
3434
ILoggerFactory factory,
3535
LogLevel minimumLogLevel,
3636
bool enableConsoleRepl,
37+
bool useLegacyReadLine,
3738
HashSet<string> featureFlags,
3839
HostDetails hostDetails,
3940
string[] additionalModules,
@@ -44,6 +45,7 @@ internal NamedPipePsesLanguageServer(
4445
factory,
4546
minimumLogLevel,
4647
enableConsoleRepl,
48+
useLegacyReadLine,
4749
featureFlags,
4850
hostDetails,
4951
additionalModules,

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal abstract class PsesLanguageServer
2727

2828
private readonly LogLevel _minimumLogLevel;
2929
private readonly bool _enableConsoleRepl;
30+
private readonly bool _useLegacyReadLine;
3031
private readonly HashSet<string> _featureFlags;
3132
private readonly HostDetails _hostDetails;
3233
private readonly string[] _additionalModules;
@@ -38,6 +39,7 @@ internal PsesLanguageServer(
3839
ILoggerFactory factory,
3940
LogLevel minimumLogLevel,
4041
bool enableConsoleRepl,
42+
bool useLegacyReadLine,
4143
HashSet<string> featureFlags,
4244
HostDetails hostDetails,
4345
string[] additionalModules,
@@ -47,6 +49,7 @@ internal PsesLanguageServer(
4749
LoggerFactory = factory;
4850
_minimumLogLevel = minimumLogLevel;
4951
_enableConsoleRepl = enableConsoleRepl;
52+
_useLegacyReadLine = useLegacyReadLine;
5053
_featureFlags = featureFlags;
5154
_hostDetails = hostDetails;
5255
_additionalModules = additionalModules;
@@ -69,6 +72,7 @@ public async Task StartAsync()
6972
_profilePaths,
7073
_featureFlags,
7174
_enableConsoleRepl,
75+
_useLegacyReadLine,
7276
_internalHost,
7377
_hostDetails,
7478
_additionalModules))

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static IServiceCollection AddPsesLanguageServices (
2020
ProfilePaths profilePaths,
2121
HashSet<string> featureFlags,
2222
bool enableConsoleRepl,
23+
bool useLegacyReadLine,
2324
PSHost internalHost,
2425
HostDetails hostDetails,
2526
string[] additionalModules)
@@ -35,6 +36,7 @@ public static IServiceCollection AddPsesLanguageServices (
3536
profilePaths,
3637
featureFlags,
3738
enableConsoleRepl,
39+
useLegacyReadLine,
3840
internalHost,
3941
hostDetails,
4042
additionalModules))

src/PowerShellEditorServices/Server/StdioPsesLanguageServer.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ internal StdioPsesLanguageServer(
2323
ProfilePaths profilePaths) : base(
2424
factory,
2525
minimumLogLevel,
26-
// Stdio server can't support an integrated console so we pass in false.
27-
false,
26+
// Stdio server can't support an integrated console so we pass in false for
27+
// enableConsoleRepl and useLegacyReadLine.
28+
enableConsoleRepl: false,
29+
useLegacyReadLine: false,
2830
featureFlags,
2931
hostDetails,
3032
additionalModules,

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,26 @@ public static PowerShellContextService Create(
171171
ProfilePaths profilePaths,
172172
HashSet<string> featureFlags,
173173
bool enableConsoleRepl,
174+
bool useLegacyReadLine,
174175
PSHost internalHost,
175176
HostDetails hostDetails,
176177
string[] additionalModules
177178
)
178179
{
179180
var logger = factory.CreateLogger<PowerShellContextService>();
180181

181-
// PSReadLine can only be used when -EnableConsoleRepl is specified otherwise
182-
// issues arise when redirecting stdio.
182+
// We should only use PSReadLine if we specificied that we want a console repl
183+
// and we have not explicitly said to use the legacy ReadLine.
184+
// We also want it if we are either:
185+
// * On Windows on any version OR
186+
// * On Linux or macOS on any version greater than or equal to 7
187+
bool shouldUsePSReadLine = enableConsoleRepl && !useLegacyReadLine
188+
&& (VersionUtils.IsWindows || !VersionUtils.IsPS6);
189+
183190
var powerShellContext = new PowerShellContextService(
184191
logger,
185192
languageServer,
186-
featureFlags.Contains("PSReadLine") && enableConsoleRepl);
193+
shouldUsePSReadLine);
187194

188195
EditorServicesPSHostUserInterface hostUserInterface =
189196
enableConsoleRepl

src/PowerShellEditorServices/Utility/VersionUtils.cs

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ internal static class VersionUtils
4848
/// True if we are running in PowerShell 7, false otherwise.
4949
/// </summary>
5050
public static bool IsPS7 { get; } = PSVersion.Major == 7;
51+
52+
/// <summary>
53+
/// True if we are running in on Windows, false otherwise.
54+
/// </summary>
55+
public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
5156
}
5257

5358
internal static class PowerShellReflectionUtils

0 commit comments

Comments
 (0)