Skip to content

Commit dbd0e46

Browse files
Additional changes to allow PSReadLine to work in CLM (#1290)
* Use PSReadLine in CLM * update PSRL version check for CLM * feedback * add workaround for PSGet behavior Co-authored-by: Tyler Leonhardt (POWERSHELL) <[email protected]>
1 parent 2f52bb6 commit dbd0e46

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,18 @@ task RestorePsesModules -After Build {
406406

407407
$splatParameters = @{
408408
Name = $moduleName
409-
MinimumVersion = $moduleInstallDetails.MinimumVersion
410-
MaximumVersion = $moduleInstallDetails.MaximumVersion
411409
AllowPrerelease = $moduleInstallDetails.AllowPrerelease
412410
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
413411
Path = $submodulePath
414412
}
415413

414+
# Only add Min and Max version if we're doing a stable release.
415+
# This is due to a PSGet issue with AllowPrerelease not installing the latest preview.
416+
if (!$moduleInstallDetails.AllowPrerelease) {
417+
$splatParameters.MinimumVersion = $moduleInstallDetails.MinimumVersion
418+
$splatParameters.MaximumVersion = $moduleInstallDetails.MaximumVersion
419+
}
420+
416421
Write-Host "`tInstalling module: ${moduleName} with arguments $(ConvertTo-Json $splatParameters)"
417422

418423
Save-Module @splatParameters

modules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"MaximumVersion":"1.99"
99
},
1010
"PSReadLine":{
11-
"MinimumVersion":"2.0.0"
11+
"MinimumVersion":"2.0.2"
1212
}
1313
}

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().AddCommand("prompt");
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 -ge '2.0.2' }} |
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.Replace("'", "''")}'
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)