Skip to content

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.ps1 script 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

  1. dprothero commented on Apr 4, 2019

    @dprothero

    Is this why backticks aren't working in the terminal? (I'm having the issue documented on #1299)

    Get-Module PSReadLine returns null for me.

  2. rkeithhill commented on Apr 5, 2019

    @rkeithhill
    Contributor

    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).

  3. sba923 commented on Apr 5, 2019

    @sba923
    Author

    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).

  4. rkeithhill commented on Apr 5, 2019

    @rkeithhill
    Contributor

    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.:

    "powershell.developer.featureFlags": [ "PSReadLine" ],
    
  5. sba923 commented on Apr 5, 2019

    @sba923
    Author

    Tada! With that line added, I get the expected behavior.

    PowerShell Integrated Console
    
    2019-04-05 17:49:36.671: '\\sba1606\private_sba$\profile.ps1' starting...
    […]
    2019-04-05 17:49:37.300: '\\sba1606\private_sba$\PowerShell\CheckPSReadLineStatus.ps1' starting...
    PSReadline version 2.0.0 beta4 is loaded
    2019-04-05 17:49:37.321: '\\sba1606\private_sba$\PowerShell\CheckPSReadLineStatus.ps1' exiting.        
    2019-04-05 17:49:37.404: line 549: 0.733s elapsed (+0.312s)
    2019-04-05 17:49:36.671: '\\sba1606\private_sba$\profile.ps1' exiting.
    2019-04-05 17:49:37.462: 'C:\Users\steph\OneDrive\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1' starting...
    2019-04-05 17:49:37.625: '\\sba1606\private_sba$\PowerShell\CheckPSReadLineStatus.ps1' starting...
    PSReadline version 2.0.0 beta4 is loaded
    2019-04-05 17:49:37.696: '\\sba1606\private_sba$\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)
    

    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" ;-)

  6. rkeithhill commented on Apr 5, 2019

    @rkeithhill
    Contributor

    this was a documented requirement for version 2.0.0 of the preview?

    Indeed it was.

  7. rkeithhill commented on Apr 5, 2019

    @rkeithhill
    Contributor

    Yeah, I'll go ahead and close this one. We have the link to that other defect in one of the messages above.

  8. TylerLeonhardt commented on Apr 5, 2019

    @TylerLeonhardt
    Member

    Thanks Keith Hill (@rkeithhill). Stéphane BARIZIEN (@sba923) PSRL will be on by default for Windows starting with the next release of the preview.

  9. sba923 commented on Apr 5, 2019

    @sba923
    Author

    And of course it'll come with PSRL beta4 or newer 😎

  10. gwojan commented on Apr 5, 2019

    @gwojan

    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).

    Keith Hill (@rkeithhill) Where might we find PSReadLine 2.0.0 beta4? I'm currently using ms-vscode.powershell-preview-2.0.1 but (Get-Module PSReadLine).ModuleBase reports PSReadLine is loading from my profile directory.

    Is PSReadLine supposed to be load from the PowerShell Extension modules directory? The ~\.vscode\extensions\ms-vscode.powershell-1.12.0\modules directory 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?

  11. TylerLeonhardt commented on Apr 5, 2019

    @TylerLeonhardt
    Member

    PSReadLine should be loaded from:

    ~\.vscode\extensions\ms-vscode.powershell-preview-2.0.1\modules
    

    assuming you are using the PowerShell Preview extension...

    If you see:

    ~\.vscode\extensions\ms-vscode.powershell-1.12.0\modules
    

    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.

  12. TylerLeonhardt commented on Apr 5, 2019

    @TylerLeonhardt
    Member
  13. gwojan commented on Apr 5, 2019

    @gwojan

    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.

    > (Get-Module PSReadLine).ModuleBase
    C:\Users\bubba\Documents\PowerShell\Modules\PSReadLine\2.0.0
    
    > code --list-extensions | rg powershell
    ms-vscode.powershell-preview
    
    > $env:PSModulePath.Split(';')
    C:\Users\bubba\Documents\PowerShell\Modules
    C:\Program Files\PowerShell\Modules
    c:\program files\powershell\6\Modules
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
    C:\Users\bubba\.vscode-insiders\extensions\ms-vscode.powershell-preview-2.0.1\modules
    
    > Get-Module -List PSReadLine | select Name, Version, ModuleBase
    Name       Version ModuleBase
    ----       ------- ----------
    PSReadLine 2.0.0   C:\Users\bubba\Documents\PowerShell\Modules\PSReadLine\2.0.0
    PSReadLine 2.0.0   C:\Program Files\PowerShell\Modules\PSReadLine\2.0.0
    PSReadLine 2.0.0   C:\program files\powershell\6\Modules\PSReadLine
    PSReadLine 2.0.0   C:\Users\bubba\.vscode-insiders\extensions\ms-vscode.powershell-preview-2.0.1\modules\PSReadLine\2.0.0
    
  14. SydneyhSmith commented on Apr 9, 2019

    @SydneyhSmith
    Collaborator

    Greg Wojan (@gwojan) what version of PowerShell are you using? Just to confirm, you have the feature flag on, correct?

  15. rjmholt commented on Apr 9, 2019

    @rjmholt
    Contributor

    Also, what's the output of:

    gmo -list PSReadLine | % { $_.PrivateData.PSData.Prerelease }

    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.

  16. sba923 commented on Apr 10, 2019

    @sba923
    Author

    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.ps1 to scan the directories on $env:PSModulePath for PSRL versions
    • CheckPSReadLineStatus.ps1 to be called from profile scripts and check if PSRL is loaded and what version is loaded.

    HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions