Repository navigation
PSReadLine doesn't get loaded on some systems (and behaves unexpectedly if loaded manually) #1834
Description
Issue Description
While helping out with issue #1570 I had to replace all instances of PSReadLine on my systems with 2.0.0 beta4, and to make sure VScode would either run with that version of PSReadLine, or that a workaround from Flavien MICHALECZEK (@fMichaleczek) would be in place.
To do this, I have instrumented my Microsoft.VSCode_profile.ps1 with code that checks the output of Get-Module PSReadLine so as to check which version of PSReadLine is be used.
On some machines, I noticed that Get-Module PSReadLine returns $null.
I have modified the instrumentation so that it would load PSReadLine using Import-Module PSReadLine when PSReadLine is found not to be loaded. When this is done, PSReadLine does get loaded and enabled, but doesn't function as expected: saved-on-disk history is not restored, syntax highlighing is not performed.
Attached are:
- the
CheckPSReadLineStatus.ps1script that checks whether PSReadLine is loaded and loads it if not - the complete
Microsoft.VSCode_profile.ps1
On a system where everything works fine the integrated console displays:
PowerShell Integrated Console
[...]
2019-04-02 06:53:49.503: 's:\PowerShell\CheckPSReadLineStatus.ps1' starting...
PSReadline version 2.0.0 beta4 is loaded
2019-04-02 06:53:49.518: 's:\PowerShell\CheckPSReadLineStatus.ps1' exiting.
2019-04-02 06:53:49.520: line 549: 2.749s elapsed (+1.538s)
2019-04-02 06:53:46.771: 'S:\profile.ps1' exiting.
2019-04-02 06:53:49.546: 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1' starting...
2019-04-02 06:53:49.575: 's:\PowerShell\CheckPSReadLineStatus.ps1' starting...
PSReadline version 2.0.0 beta4 is loaded
2019-04-02 06:53:49.582: 's:\PowerShell\CheckPSReadLineStatus.ps1' exiting.
PSReadline version 2.0.0 beta4 is loaded
No 'endless loop' workaround should be needed (PSReadLine is version 2.0.0 beta4)
On a system where the problem occurs the output is:
PowerShell Integrated Console
2019-04-01 21:33:16.814: 'S:\profile.ps1' starting...
[...]
2019-04-01 21:33:18.997: 's:\PowerShell\CheckPSReadLineStatus.ps1' starting...
PSReadLine is not loaded!!!???
2019-04-01 21:33:19.000: 's:\PowerShell\CheckPSReadLineStatus.ps1' exiting.
2019-04-01 21:33:19.001: line 549: 2.187s elapsed (+0.841s)
2019-04-01 21:33:16.814: 'S:\profile.ps1' exiting.
2019-04-01 21:33:19.022: 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1' starting...
2019-04-01 21:33:19.042: 's:\PowerShell\CheckPSReadLineStatus.ps1' starting...
PSReadLine is not loaded!!!???
PSModulePath is:
C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Users\steph\.vscode\extensions\ms-vscode.powershell-preview-2.0.1\modules
Attempting to Import-Module PSReadLine
VERBOSE: Loading module from path 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Modules\PSReadLine\2.0.0\PSReadLine.psd1'.
VERBOSE: Cannot verify the Microsoft .NET Framework version 4.6.1 because it is not included in the list of permitted versions.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Modules\PSReadLine\2.0.0\PSReadLine.format.ps1xml'.
VERBOSE: Loading module from path 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Modules\PSReadLine\2.0.0\Microsoft.PowerShell.PSReadLine2.dll'.
VERBOSE: Importing cmdlet 'Get-PSReadLineOption'.
VERBOSE: Importing cmdlet 'Set-PSReadLineOption'.
VERBOSE: Importing cmdlet 'Set-PSReadLineKeyHandler'.
VERBOSE: Importing cmdlet 'Get-PSReadLineKeyHandler'.
VERBOSE: Importing cmdlet 'Remove-PSReadLineKeyHandler'.
VERBOSE: Loading module from path 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Modules\PSReadLine\2.0.0\PSReadLine.psm1'.
VERBOSE: Exporting function 'PSConsoleHostReadLine'.
VERBOSE: Exporting cmdlet 'Get-PSReadLineOption'.
VERBOSE: Exporting cmdlet 'Set-PSReadLineOption'.
VERBOSE: Exporting cmdlet 'Set-PSReadLineKeyHandler'.
VERBOSE: Exporting cmdlet 'Get-PSReadLineKeyHandler'.
VERBOSE: Exporting cmdlet 'Remove-PSReadLineKeyHandler'.
VERBOSE: Importing cmdlet 'Get-PSReadLineKeyHandler'.
VERBOSE: Importing cmdlet 'Get-PSReadLineOption'.
VERBOSE: Importing cmdlet 'Remove-PSReadLineKeyHandler'.
VERBOSE: Importing cmdlet 'Set-PSReadLineKeyHandler'.
VERBOSE: Importing cmdlet 'Set-PSReadLineOption'.
VERBOSE: Importing function 'PSConsoleHostReadLine'.
2019-04-01 21:33:19.387: 's:\PowerShell\CheckPSReadLineStatus.ps1' invoking itself after Import-Module...
2019-04-01 21:33:19.399: 'S:\PowerShell\CheckPSReadLineStatus.ps1' starting...
PSReadline version 2.0.0 beta4 is loaded
2019-04-01 21:33:19.411: 'S:\PowerShell\CheckPSReadLineStatus.ps1' exiting.
PSReadline version 2.0.0 beta4 is loaded
No 'endless loop' workaround should be needed (PSReadLine is version 2.0.0 beta4)
Expected Behaviour
PSReadLine should always be loaded in the PowerShell Integrated Console
Actual Behaviour
On some systems PSReadLine doesn't get loaded, and when loaded by invoking Import-Module PSReadLine from Microsoft.VSCode_profile.ps1 it doesn't behave properly: saved-on-disk history is not restored, syntax highlighing is not done.
Attached Logs
(PSES logs from a system where the problem occurs)
System Details
System Details Output from a system where the problem occurs
### VSCode version: 1.32.3 a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4 x64
### VSCode extensions:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
### PSES version: 2.0.0.0
### PowerShell version:
Name Value
---- -----
PSVersion 5.1.17763.316
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.316
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PSES_logs_SBAHOME_1554181156-ad5e7b0b-733a-48f5-8290-4b9400aa3d881554180886264_20190402.zip
Microsoft.VSCode_profile.ps1.zip
CheckPSReadLineStatus.zip
Activity
dprothero commentedon Apr 4, 2019
Is this why backticks aren't working in the terminal? (I'm having the issue documented on #1299)
Get-Module PSReadLinereturns null for me.rkeithhill commentedon Apr 5, 2019
That is why backticks aren't working in v1.12.0 of the extension. This specific issue was filed against the PowerShell Preview (v2.0.1) which can load PSReadLine with a number of caveats (setting FeatureFlags and grabbing PSReadLine 2.0.0 beta4).
sba923 commentedon Apr 5, 2019
What's that point about FeatureFlags? Did I miss something that needs to be done to enable PSReadLine with the PowerShell [extension] Preview? If that's the case, my apologies, because this will render this issue moot...
Note: Even with Windows PowerShell 5.1, I sometimes get "PSReadline not loaded. Console will run without PSReadline." (or whatever the exact message is).
rkeithhill commentedon Apr 5, 2019
Yup, our intent was to not require the PSReadLine feature flag for the 2.0.1 preview release. But there's a bug that prevents PSRL from loading in that preview unless you specify the feature flag e.g.:
sba923 commentedon Apr 5, 2019
Tada! With that line added, I get the expected behavior.
I will test on the other affected systems at home.
For some reason I must've added the FeatureFlag setting on some but not all of my systems -- because this was a documented requirement for version 2.0.0 of the preview?
Shall we close this issue and optionally link it to the bug you were referring to?
P.S. Sorry for the "noise" ;-)
rkeithhill commentedon Apr 5, 2019
Indeed it was.
rkeithhill commentedon Apr 5, 2019
Yeah, I'll go ahead and close this one. We have the link to that other defect in one of the messages above.
TylerLeonhardt commentedon Apr 5, 2019
Thanks Keith Hill (@rkeithhill). Stéphane BARIZIEN (@sba923) PSRL will be on by default for Windows starting with the next release of the preview.
sba923 commentedon Apr 5, 2019
And of course it'll come with PSRL beta4 or newer 😎
gwojan commentedon Apr 5, 2019
Keith Hill (@rkeithhill) Where might we find
PSReadLine 2.0.0 beta4? I'm currently usingms-vscode.powershell-preview-2.0.1but(Get-Module PSReadLine).ModuleBasereportsPSReadLineis loading from my profile directory.Is
PSReadLinesupposed to be load from the PowerShell Extension modules directory? The~\.vscode\extensions\ms-vscode.powershell-1.12.0\modulesdirectory is being appended to my$env:PSModulePath. It seems like it should be prepended to allow extension modules to be loaded preferentially. Am I missing something?TylerLeonhardt commentedon Apr 5, 2019
PSReadLine should be loaded from:
assuming you are using the PowerShell Preview extension...
If you see:
this probably means you're actually running the Stable version of the PowerShell extension and you should disable that and enable the PowerShell Preview extension.
TylerLeonhardt commentedon Apr 5, 2019
Here's the official blog post with all of the steps:
https://devblogs.microsoft.com/powershell/announcing-the-powershell-preview-extension-in-vscode/
gwojan commentedon Apr 5, 2019
TylerLeonhardt Um, yeah... 😞 PSReadLine does not appear to be loading from the PowerShell Extension directory but the preview is definitely installed. Is the import of PSReadLine done explicitly by the PowerShell Extension? To my eyes it seems PSReadLine is just loading from the first module it finds. If I disable the module in my profile directory PSReadLine loads from
$env:ProgramFiles\PowerShell\Modules. Am I approaching this wrong?BTW, PSReadLine vi-mode works like I would expect.
SydneyhSmith commentedon Apr 9, 2019
Greg Wojan (@gwojan) what version of PowerShell are you using? Just to confirm, you have the feature flag on, correct?
rjmholt commentedon Apr 9, 2019
Also, what's the output of:
We do our best to load the latest PSReadLine we find, but there's no ordering of prerelease tags. You may want to delete some of your PSReadLine installations there.
sba923 commentedon Apr 10, 2019
I did have to scan my systems for older versions of PSRL.
I wrote the attached two scripts to help me out with that:
CheckPSReadLineOnPSModulePath.ps1to scan the directories on$env:PSModulePathfor PSRL versionsCheckPSReadLineStatus.ps1to be called from profile scripts and check if PSRL is loaded and what version is loaded.HTH