Skip to content

PSReadline char @ is added in the output of all scripts #2274

Closed
PowerShell/PowerShellEditorServices
#1092

Description

Issue Description

I am experiencing a problem with PSReadline random chars being added to the output of all scripts.

image

After the script is done, press ENTER and it shows the error as above.

Attached Logs

Follow the instructions in the README about
capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.17763
VSCode 1.39.2
PowerShell Extension Version 2019.11.0

PowerShell Information

Name Value
PSVersion 5.1.17763.771
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.17763.771
BuildVersion 10.0.17763.771
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
beautify HookyQR 1.5.0
gitlens eamodio 10.1.1
material-icon-theme PKief 3.9.1
open-in-browser techer 2.0.0
powershell-preview ms-vscode 2019.11.0
theme-monokai-pro-vscode monokai 1.1.14
vscode-wakatime WakaTime 2.2.1

Activity

  1. ghost added
    Needs: Triage
    on Nov 4, 2019
  2. bgelens commented on Nov 4, 2019

    @bgelens

    I have a similar thing. F8 for run selection will insert @ on the new prompt after running the selection

    image

    $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      7.0.0-preview.5
    PSEdition                      Core
    GitCommitId                    7.0.0-preview.5
    OS                             Darwin 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
  3. TylerLeonhardt commented on Nov 4, 2019

    @TylerLeonhardt
    Member

    Yes this seems to be an issue in PSReadLine. I'm investigating it and can repro

  4. TylerLeonhardt commented on Nov 4, 2019

    @TylerLeonhardt
    Member

    Thankfully, the @ in the prompt does not impact F8'ing code so you can still do that even if there's a @ (or anything really) sitting in your prompt

  5. bgelens commented on Nov 4, 2019

    @bgelens

    True. They do stack up though :)

    image

  6. TylerLeonhardt commented on Nov 4, 2019

    @TylerLeonhardt
    Member

    This was introduced in PowerShell/PowerShellEditorServices#1072

    What's the saying? "1 bug fixed, 2 more appear"? 😅

  7. rjmholt commented on Nov 4, 2019

    @rjmholt
    Contributor
  8. rjmholt commented on Nov 4, 2019

    @rjmholt
    Contributor

    So I've done some debugging here and it looks like our API with PSReadLine isn't quite right.

    Here is where we implement our own version of Console.ReadLine() which we can cancel so as to run PowerShell commands for things like completions in the background.

    Currently, when it cancels, it sends back default(ConsoleKeyInfo) to PSReadLine. This is effectively as NUL char ('\0'). I suspect that either PSReadLine or xtermjs turns that into an @.

    I played with turning it into a space, returning new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, shift: false, alt: false, control: false). It's not perfect, but it's a lot less problematic than @.

    Short term, we should find a character that is as helpful as possible that we can return here.

    Medium term, we should work with Dongbo Wang (@daxian-dbw) to change the way we interact with PSReadLine either to make this bool TryReadKey(out ConsoleKeyInfo cki) (or with a nullable), or look into idle eventing (Dongbo Wang (@daxian-dbw)'s suggestion) for running commands behind the prompt.

  9. added
    Issue-Bug
    and removed
    Needs: Triage
    on Nov 4, 2019
  10. rjmholt commented on Nov 4, 2019

    @rjmholt
    Contributor

    Give this VSIX a try and let me know if it solves things. Przemysław Kłys (@PrzemyslawKlys) I'm particularly interested in whether it solves any of your other bugs.

    psvsix.zip

  11. bgelens commented on Nov 5, 2019

    @bgelens

    Rob Holt (@rjmholt) That fixes it for me!

  12. ghost added
    Needs: Maintainer Attention
    on Nov 5, 2019
  13. PrzemyslawKlys commented on Nov 5, 2019

    @PrzemyslawKlys
    ContributorAuthor
    PS> Unable to find type [Microsoft.PowerShell.PSConsoleReadLine].
    At line:1 char:71
    + ... :RunClassConstructor([Microsoft.PowerShell.PSConsoleReadLine].TypeHan ...
    +                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (Microsoft.PowerShell.PSConsoleReadLine:TypeName) [], RuntimeException
        + FullyQualifiedErrorId : TypeNotFound
    

    That's what I get after installing and running this extension. So I guess PSReadLine is not working :-)

  14. 3 remaining items

  15. TylerLeonhardt commented on Nov 5, 2019

    @TylerLeonhardt
    Member

    Sorry I need the prerelease version.

    (gmo PSReadLine).PrivateData.PSData
    

    Should be in there.

  16. PrzemyslawKlys commented on Nov 5, 2019

    @PrzemyslawKlys
    ContributorAuthor
    PS C:\Users\\Desktop\GitHUB\PSWriteHTML> (gmo PSReadLine).PrivateData.PSData
    PS C:\Users\\Desktop\GitHUB\PSWriteHTML> (gmo PSReadLine -ListAvailable).PrivateData.PSData
    
    Name                           Value
    ----                           -----
    Prerelease                     beta2
    
  17. TylerLeonhardt commented on Nov 5, 2019

    @TylerLeonhardt
    Member

    One last thing:

    gci ~/.vscode/extensions/ms-vscode.powershell-preview-2019.11.0/modules
    

    Or if you use vscode insiders:

    gci ~/.vscode-insiders/extensions/ms-vscode.powershell-preview-2019.11.0/modules
    
  18. PrzemyslawKlys commented on Nov 5, 2019

    @PrzemyslawKlys
    ContributorAuthor
    PS C:\Users\\Desktop\GitHUB\PSWriteHTML> gci ~/.vscode/extensions/ms-vscode.powershell-preview-2019.11.1/modules
    
    
        Directory: C:\Users\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----        11/5/2019   3:38 PM                docs
    d-----        11/5/2019   3:38 PM                Plaster
    d-----        11/5/2019   3:38 PM                PowerShellEditorServices
    d-----        11/5/2019   3:38 PM                PowerShellEditorServices.VSCode
    d-----        11/5/2019   3:38 PM                PSReadLine
    d-----        11/5/2019   3:38 PM                PSScriptAnalyzer
    -a----        11/5/2019   3:38 PM            370 README.md
    
  19. TylerLeonhardt commented on Nov 5, 2019

    @TylerLeonhardt
    Member

    Ok the problem here is that we're not loading the correct PSReadLine.

  20. rjmholt commented on Nov 5, 2019

    @rjmholt
    Contributor

    Try Install-Module -Force PSReadLine -AllowPrelease -- that should put a newer PSReadLine earlier on your path

  21. rjmholt commented on Nov 5, 2019

    @rjmholt
    Contributor

    I suspect we need to update our PSRL load logic -- the issue is that we need something in a particular beta version (and PSRL's version scheme combined with the module system's support for prerelease versions makes life hard)

  22. PrzemyslawKlys commented on Nov 6, 2019

    @PrzemyslawKlys
    ContributorAuthor

    So that fix works but still the other problem is there:

    image

  23. PrzemyslawKlys commented on Nov 6, 2019

    @PrzemyslawKlys
    ContributorAuthor

    It seems to be related to how you handle prompt. It seems you "add" your own prompt with PSReadLine, when it's already added.

    if I use something like this:

    $DirectoryPath = "$Env:USERPROFILE\Desktop"
    "$DirectoryPath\ExportDCInventory-$($DC.HostName).xml"

    The output will be:

    image

    But then if you press Enter it will bring proper prompt back. So either you have to skip adding your own prompt or overwrite the original one.

  24. rjmholt commented on Nov 6, 2019

    @rjmholt
    Contributor

    Here is the script we use to find PSReadLine, which specifically drops beta2.

    It may be that the PSConsoleReadLine type is already loaded from the wrong PSRL at that point in some cases. PSRL's versioning makes this hard for us unfortunately.

  25. rjmholt commented on Nov 6, 2019

    @rjmholt
    Contributor

    It seems to be related to how you handle prompt. It seems you "add" your own prompt with PSReadLine, when it's already added.

    Yes that's probably us renewing the prompt improperly. We already fudge the prompt correctly in a number of cases, it just doesn't look like it. We can continue that discussion in #2276 if that's alright. Just want to keep the discussions separate (primarily so I don't get confused).

  26. PrzemyslawKlys commented on Nov 6, 2019

    @PrzemyslawKlys
    ContributorAuthor

    Just to add, installing the new .vsix on another machine:

    VERBOSE: Invoking Start-EditorServicesHost
    VERBOSE: Start-EditorServicesHost returned Microsoft.PowerShell.EditorServices.Hosting.EditorServicesHost
    VERBOSE: Writing session file with contents:
    VERBOSE: 
    {"languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_uyqaojrq.nxm","debugServiceTransport":"NamedPipe","status 
    ":"started","debugServicePipeName":"\\\\.\\pipe\\PSES_o3vccg0r.ee3"}
    VERBOSE: Wrote out session file
    VERBOSE: 
    #-- Waiting for EditorServicesHost to complete execution ---------------------
    You cannot call a method on a null-valued expression.
    At C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules\PowerShellEditorServices\Commands\Public\Import-
    EditorCommand.ps1:61 char:9
    +         $extensionService = $psEditor.GetType().
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
    
    You cannot call a method on a null-valued expression.
    At C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules\PowerShellEditorServices\Commands\Public\Import- 
    EditorCommand.ps1:65 char:9
    +         $editorCommands = $extensionService.GetType().
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
    

    It seems like the VSIX (the one .zipped) is missing some paths.

    PS C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules> dir
    
    
        Directory: C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----       06.11.2019     20:31                docs
    d-----       06.11.2019     20:31                Plaster
    d-----       06.11.2019     20:31                PowerShellEditorServices
    d-----       06.11.2019     20:31                PowerShellEditorServices.VSCode
    d-----       06.11.2019     20:31                PSReadLine
    d-----       06.11.2019     20:31                PSScriptAnalyzer
    ----                -------------         ------ ----
    d-----       06.11.2019     20:31                2.0.0
    
    
    PS C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules\PSReadLine> cd .\2.0.0
    PS C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules\PSReadLine\2.0.0> ls
    
    
        Directory: C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules\PSReadLine\2.0.0
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----       06.11.2019     20:31         265296 Microsoft.PowerShell.PSReadLine2.dll
    
    
    PS C:\Users\przemyslaw.klys\.vscode\extensions\ms-vscode.powershell-preview-2019.11.1\modules\PSReadLine\2.0.0>
    

    Not sure what is missing on my home machine.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-PSReadLineIssue-Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions