Skip to content

Commit f8a08c4

Browse files
Use PSReadLine in CLM
1 parent 07b4131 commit f8a08c4

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ public void Initialize(
415415

416416
if (powerShellVersion.Major >= 5 &&
417417
this.isPSReadLineEnabled &&
418-
// TODO: Figure out why PSReadLine isn't working in ConstrainedLanguage mode.
419-
initialRunspace.SessionStateProxy.LanguageMode == PSLanguageMode.FullLanguage &&
420418
PSReadLinePromptContext.TryGetPSReadLineProxy(logger, initialRunspace, out PSReadLineProxy proxy))
421419
{
422420
this.PromptContext = new PSReadLinePromptContext(

src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ private async Task WritePromptStringToHostAsync(CancellationToken cancellationTo
729729
{
730730
}
731731

732-
PSCommand promptCommand = new PSCommand().AddScript("prompt");
732+
PSCommand promptCommand = new PSCommand().AddScript("prompt", useLocalScope: true);
733733

734734
cancellationToken.ThrowIfCancellationRequested();
735735
string promptString =

src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,35 @@
1414

1515
namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext
1616
{
17+
using System.IO;
1718
using System.Management.Automation;
1819

1920
internal class PSReadLinePromptContext : IPromptContext
2021
{
21-
private const string ReadLineInitScript = @"
22+
private static readonly string _psReadLineModulePath = Path.Combine(
23+
Path.GetDirectoryName(typeof(PSReadLinePromptContext).Assembly.Location),
24+
"..",
25+
"..",
26+
"..",
27+
"PSReadLine");
28+
29+
private static readonly string ReadLineInitScript = $@"
2230
[System.Diagnostics.DebuggerHidden()]
2331
[System.Diagnostics.DebuggerStepThrough()]
2432
param()
25-
end {
33+
end {{
2634
$module = Get-Module -ListAvailable PSReadLine |
27-
Where-Object { $_.Version -gt '2.0.0' -or ($_.Version -eq '2.0.0' -and -not $_.PrivateData.PSData.Prerelease) } |
35+
Where-Object {{ $_.Version -gt '2.0.0' -or ($_.Version -eq '2.0.0' -and -not $_.PrivateData.PSData.Prerelease) }} |
2836
Sort-Object -Descending Version |
2937
Select-Object -First 1
30-
if (-not $module) {
31-
return
32-
}
38+
if (-not $module) {{
39+
Import-Module {_psReadLineModulePath}
40+
return [Microsoft.PowerShell.PSConsoleReadLine]
41+
}}
3342
3443
Import-Module -ModuleInfo $module
3544
return [Microsoft.PowerShell.PSConsoleReadLine]
36-
}";
45+
}}";
3746

3847
private static readonly Lazy<CmdletInfo> s_lazyInvokeReadLineForEditorServicesCmdletInfo = new Lazy<CmdletInfo>(() =>
3948
{

0 commit comments

Comments
 (0)