Skip to content

Additional changes to allow PSReadLine to work in CLM #1290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,18 @@ task RestorePsesModules -After Build {

$splatParameters = @{
Name = $moduleName
MinimumVersion = $moduleInstallDetails.MinimumVersion
MaximumVersion = $moduleInstallDetails.MaximumVersion
AllowPrerelease = $moduleInstallDetails.AllowPrerelease
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}

# Only add Min and Max version if we're doing a stable release.
# This is due to a PSGet issue with AllowPrerelease not installing the latest preview.
if (!$moduleInstallDetails.AllowPrerelease) {
$splatParameters.MinimumVersion = $moduleInstallDetails.MinimumVersion
$splatParameters.MaximumVersion = $moduleInstallDetails.MaximumVersion
}

Write-Host "`tInstalling module: ${moduleName} with arguments $(ConvertTo-Json $splatParameters)"

Save-Module @splatParameters
Expand Down
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"MaximumVersion":"1.99"
},
"PSReadLine":{
"MinimumVersion":"2.0.0"
"MinimumVersion":"2.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ public void Initialize(

if (powerShellVersion.Major >= 5 &&
this.isPSReadLineEnabled &&
// TODO: Figure out why PSReadLine isn't working in ConstrainedLanguage mode.
initialRunspace.SessionStateProxy.LanguageMode == PSLanguageMode.FullLanguage &&
PSReadLinePromptContext.TryGetPSReadLineProxy(logger, initialRunspace, out PSReadLineProxy proxy))
{
this.PromptContext = new PSReadLinePromptContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ private async Task WritePromptStringToHostAsync(CancellationToken cancellationTo
{
}

PSCommand promptCommand = new PSCommand().AddScript("prompt");
PSCommand promptCommand = new PSCommand().AddCommand("prompt");

cancellationToken.ThrowIfCancellationRequested();
string promptString =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,35 @@

namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext
{
using System.IO;
using System.Management.Automation;

internal class PSReadLinePromptContext : IPromptContext
{
private const string ReadLineInitScript = @"
private static readonly string _psReadLineModulePath = Path.Combine(
Path.GetDirectoryName(typeof(PSReadLinePromptContext).Assembly.Location),
"..",
"..",
"..",
"PSReadLine");

private static readonly string ReadLineInitScript = $@"
[System.Diagnostics.DebuggerHidden()]
[System.Diagnostics.DebuggerStepThrough()]
param()
end {
end {{
$module = Get-Module -ListAvailable PSReadLine |
Where-Object { $_.Version -gt '2.0.0' -or ($_.Version -eq '2.0.0' -and -not $_.PrivateData.PSData.Prerelease) } |
Where-Object {{ $_.Version -ge '2.0.2' }} |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth taking the version here out into a constant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that next time 😅 I really don't want to test on my SAW again lol

Sort-Object -Descending Version |
Select-Object -First 1
if (-not $module) {
return
}
if (-not $module) {{
Import-Module '{_psReadLineModulePath.Replace("'", "''")}'
return [Microsoft.PowerShell.PSConsoleReadLine]
}}

Import-Module -ModuleInfo $module
return [Microsoft.PowerShell.PSConsoleReadLine]
}";
}}";

private static readonly Lazy<CmdletInfo> s_lazyInvokeReadLineForEditorServicesCmdletInfo = new Lazy<CmdletInfo>(() =>
{
Expand Down