Vscode-powershell: PSReadline char @ is added in the output of all scripts

Created on 4 Nov 2019  路  25Comments  路  Source: PowerShell/vscode-powershell

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|

Area-PSReadLine Issue-Bug Preview Extension

All 25 comments

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

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

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

True. They do stack up though :)

image

This was introduced in https://github.com/PowerShell/PowerShellEditorServices/pull/1072

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

/cc @daxian-dbw

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 @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 (@daxian-dbw's suggestion) for running commands behind the prompt.

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

psvsix.zip

@rjmholt That fixes it for me!

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

@rjmholt the VSIX solve the problem for me but as @PrzemyslawKlys mentioned with the VSIX version when using PowerShell 5.1 (7.0 works fine) when you "F5" you get the error @PrzemyslawKlys posted.

Is this a new bug in your fix? or did you just forgot to pack something in the VSIX?

@ili101 @PrzemyslawKlys can you tell me if PSReadLine is available in your Integrated Console? (Get-Module PSReadLine)

image

It is.

Sorry I need the prerelease version.

(gmo PSReadLine).PrivateData.PSData

Should be in there.

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

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

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

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

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)

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

image

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.

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.

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 https://github.com/PowerShell/vscode-powershell/issues/2276 if that's alright. Just want to keep the discussions separate (primarily so I don't get confused).

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.

Was this page helpful?
0 / 5 - 0 ratings