Skip to content
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

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

Closed
PrzemyslawKlys opened this issue Nov 4, 2019 · 25 comments · Fixed by PowerShell/PowerShellEditorServices#1092
Labels

Comments

@PrzemyslawKlys
Copy link
Contributor

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
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 4, 2019
@bgelens
Copy link

bgelens commented Nov 4, 2019

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

@TylerLeonhardt
Copy link
Member

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

@TylerLeonhardt
Copy link
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

@bgelens
Copy link

bgelens commented Nov 4, 2019

True. They do stack up though :)

image

@TylerLeonhardt
Copy link
Member

This was introduced in PowerShell/PowerShellEditorServices#1072

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

@rjmholt
Copy link
Contributor

rjmholt commented Nov 4, 2019

/cc @daxian-dbw

@rjmholt
Copy link
Contributor

rjmholt commented Nov 4, 2019

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.

@rjmholt
Copy link
Contributor

rjmholt commented Nov 4, 2019

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

@bgelens
Copy link

bgelens commented Nov 5, 2019

@rjmholt That fixes it for me!

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Nov 5, 2019
@PrzemyslawKlys
Copy link
Contributor Author

PrzemyslawKlys commented Nov 5, 2019

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

@ili101
Copy link

ili101 commented Nov 5, 2019

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

@TylerLeonhardt
Copy link
Member

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

@PrzemyslawKlys
Copy link
Contributor Author

image

It is.

@TylerLeonhardt
Copy link
Member

Sorry I need the prerelease version.

(gmo PSReadLine).PrivateData.PSData

Should be in there.

@PrzemyslawKlys
Copy link
Contributor Author

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

@TylerLeonhardt
Copy link
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

@PrzemyslawKlys
Copy link
Contributor Author

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

@TylerLeonhardt
Copy link
Member

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

@rjmholt
Copy link
Contributor

rjmholt commented Nov 5, 2019

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

@rjmholt
Copy link
Contributor

rjmholt commented Nov 5, 2019

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)

@PrzemyslawKlys
Copy link
Contributor Author

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

image

@PrzemyslawKlys
Copy link
Contributor Author

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.

@rjmholt
Copy link
Contributor

rjmholt commented Nov 6, 2019

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.

@rjmholt
Copy link
Contributor

rjmholt commented Nov 6, 2019

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

@PrzemyslawKlys
Copy link
Contributor Author

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants