vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

2.0.0-insiders-834: prompt gets displayed in an endless loop

Open sba923 opened this issue 8 years ago • 68 comments

Issue Description

When I open a folder containing PowerShell scripts, the integrated terminal displays the prompt in an endless loop, as if I would press and hold the Enter key for it to autorepeat.

Attached Logs

See 1539111398-a60423be-01d3-4cc1-83df-f15ead97e8aa1539111394598.zip

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.17763
VSCode 1.28.0
PowerShell Extension Version 2.0.0-insiders-834

PowerShell Information

Name Value
PSVersion 5.1.17763.1
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.17763.1
BuildVersion 10.0.17763.1
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.4.4
cpptools ms-vscode 0.19.0
csharp ms-vscode 1.16.2
path-intellisense christian-kohler 1.4.2
PowerShell ms-vscode 2.0.0-insiders-834
prettier-vscode esbenp 1.6.1
printcode nobuhito 3.0.0
vscode-color anseki 0.4.5
vscode-html-css ecmel 0.2.0
vscode-javascript-snippet-pack akamud 0.1.5
vscode-npm-script eg2 0.3.5
vscode-standardjs chenxsan 1.2.3
vscode-tidyhtml anweber 1.10.0

sba923 avatar Oct 10 '18 04:10 sba923

Seems logs didn't make it via drag-and-drop.

1539111398-a60423be-01d3-4cc1-83df-f15ead97e8aa1539111394598.zip

sba923 avatar Oct 10 '18 04:10 sba923

This seems to be the relevant part of the log:

2018-10-09 20:57:11.511 [VERBOSE] C:\projects\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommand', line 622:
    Attempting to execute command(s):
    
        
            [System.Diagnostics.DebuggerHidden()]
            [System.Diagnostics.DebuggerStepThrough()]
            param()
            return [Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]::ReadLine(
                $Host.Runspace,
                $ExecutionContext,
                $args[0]) System.Threading.CancellationToken
    

2018-10-09 20:57:11.513 [ERROR] C:\projects\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: In method 'ExecuteCommand', line 692:
    Execution of the following command(s) completed with errors:
    
        
            [System.Diagnostics.DebuggerHidden()]
            [System.Diagnostics.DebuggerStepThrough()]
            param()
            return [Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]::ReadLine(
                $Host.Runspace,
                $ExecutionContext,
                $args[0]) System.Threading.CancellationToken
    
    Error #1:
    Exception calling "ReadLine" with "3" argument(s): "The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception."
    ScriptStackTrace:
    at <ScriptBlock>, <No file>: line 5
    Exception:
       System.Management.Automation.MethodInvocationException: Exception calling "ReadLine" with "3" argument(s): "The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception." ---> System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.Keys' threw an exception. ---> System.ArgumentException: An item with the same key has already been added.
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at Microsoft.PowerShell.Keys..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.PowerShell.PSConsoleReadLine..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)
       at CallSite.Target(Closure , CallSite , Type , Object , Object , Object )
       --- End of inner exception stack trace ---
       at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
       at CallSite.Target(Closure , CallSite , Type , Object , Object , Object )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
       at System.Management.Automation.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)InnerException:
       System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.Keys' threw an exception. ---> System.ArgumentException: An item with the same key has already been added.
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at Microsoft.PowerShell.Keys..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.PowerShell.PSConsoleReadLine..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)
       at CallSite.Target(Closure , CallSite , Type , Object , Object , Object )InnerException:
       System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.Keys' threw an exception. ---> System.ArgumentException: An item with the same key has already been added.
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at Microsoft.PowerShell.Keys..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.PowerShell.PSConsoleReadLine..cctor()InnerException:
       System.ArgumentException: An item with the same key has already been added.
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at Microsoft.PowerShell.Keys..cctor()

rjmholt avatar Oct 10 '18 05:10 rjmholt

Relevant PSReadLine code: https://github.com/lzybkr/PSReadLine/blob/57bc3a65fd2bbf0b69aaed2ce395d0327de20cc0/PSReadLine/Keys.cs#L406-L419

rjmholt avatar Oct 10 '18 05:10 rjmholt

@sba923 Out of curiosity:

  • Does your normal PowerShell session support PSReadLine? I'm assuming Windows PowerShell -- if so, it might be worth installing PowerShell Core to see if its PSReadLine works for you.
  • What's your keyboard configuration? Is it US or something else? Normal layout or something like Dvorak or Colemak?
  • What's your language/culture set to? en_US, or something else?

rjmholt avatar Oct 10 '18 05:10 rjmholt

Tagging @SeeminglyScience as well, since he knows much more about PSReadLine than me

rjmholt avatar Oct 10 '18 05:10 rjmholt

Ah yeah. That's most likely the known issue with different keyboard layouts.

~Here's the PR to follow lzybkr/PSReadLine#771~

The fix has already been merged (Thank you @lzybkr!)

@sba923 here's the latest preview build for PSReadLine if you'd like to see if that fixes your issue.

@rjmholt We should consider updating the insiders build to pull a daily until that fix gets into a beta

SeeminglyScience avatar Oct 10 '18 14:10 SeeminglyScience

@SeeminglyScience - wrong PR, the fix was merged in https://github.com/lzybkr/PSReadLine/pull/768

lzybkr avatar Oct 10 '18 16:10 lzybkr

Here's my setup:

  • French Windows 10 (preinstalled by Acer)
  • English and German language packs installed
  • Windows display language set to English
  • keyboard layout = French
  • Get-Culture returns
LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)

If I switch VScode to PowerShell Core 6.1, the problem is still present.

If I switch the keyboard layout to English while the PowerShell "integrated terminal" starts, the problem disappears -- even if I later change the keyboard layout back to French.

HTH

sba923 avatar Oct 10 '18 19:10 sba923

@sba923 - note that some key bindings won't work correctly if you switch keyboard layouts after starting PowerShell - specifically the need for Shift differs between the initial and changed keyboard layouts, e.g. Alt+1 does not require Shift in English, but does for French.

I don't think this affects commonly used key bindings, but it's good to be aware of. If it does affect important bindings, I'd like the hear about it because I rely on a Win32 api that reports incorrect information after the keyboard layout change and the team needs customer feedback to justify fixing it.

lzybkr avatar Oct 10 '18 19:10 lzybkr

@sba923 sorry by "swtich to PSCore", I meant as the standalone app rather than in VSCode. But I think we are using an even newer version of PSReadLine than PSCore anyway.

Anyway, it looks like this is fixed in PSReadLine.

@SeeminglyScience maybe we can come up with a way to identify PSReadLine issues similar to how PSReadLine itself deals with them to make crashing and reporting easier? Just thinking about being more helpful to @lzybkr here :)

rjmholt avatar Oct 10 '18 20:10 rjmholt

@rjmholt I'm using PowerShell Core 6.1 next to Windows PowerShell 5.1, and don't have any prompt issues in either. Only the integrated terminal in VScode with any post-1.9.0-test-build of the PowerShell extension exhibits the problem.

@lzybkr I find it very strange that 1) there are apps that still do their keycode-to-action-or-character mapping on their own instead of relying on OS infrastructure for that 2) changing the keyboard mapping e.g. with Win+Space while an app is running (which is just... always the case) would cause problems

Where does this all tell about us getting a version of the PowerShell extension for VScode that "just works"? Do you guys have to wait for a fixed PSReadLine to be "baked into" the extension?

sba923 avatar Oct 11 '18 04:10 sba923

@sba923

Where does this all tell about us getting a version of the PowerShell extension for VScode that "just works"? Do you guys have to wait for a fixed PSReadLine to be "baked into" the extension?

Yeah this issue was just recently discovered and fixed in PSReadLine, so it hasn't made it to a beta release yet. Once that happens we can change the CI build to pull the newest release and it will be a part of the daily build bundle.

@rjmholt

@SeeminglyScience maybe we can come up with a way to identify PSReadLine issues similar to how PSReadLine itself deals with them to make crashing and reporting easier? Just thinking about being more helpful to @lzybkr here :)

Yeah we need to handle this better, even though a similar situation is unlikely to happen again. Because PSRL is invoked via PowerShellContext.ExecuteCommand any exceptions are caught, logged, optionally printed to the console, then ignored. If PSRL throws any exception, we should either fall back to old ReadLine or hard fail. Maybe in this case we should log stack trace, OS, framework, and module information into one entry for to make it a little easier to troubleshoot as well.

SeeminglyScience avatar Oct 11 '18 12:10 SeeminglyScience

Great! I'll hold my breath then ;-)

Can you explain why the PowerShell Core 6.1 based Integrated Terminal in VScode is affected by the issue, whereas pwsh.exe isn't?

sba923 avatar Oct 11 '18 19:10 sba923

@sba923 I was about to give you an explanation that pwsh.exe has a lower version of PSReadLine, but it turns out it's also on beta3. According to @SteveL-MSFT this issue should be occurring in pwsh.exe 6.1.0 as well, unless you have a lower version of PSReadLine (like 1.2) overriding it somewhere.

Anyway, it will be fixed in the next PSReadLine release.

rjmholt avatar Oct 11 '18 20:10 rjmholt

@rjmholt Here's what PSReadLine's I have on my system:

  • on disk:
ProductVersion   FileVersion      FileName
--------------   -----------      --------
10.0.17763.1     10.0.17763.1     C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0\Microsoft.PowerShell.PSReadline.dll
10.0.17763.1     10.0.17763.1     C:\Windows\WinSxS\msil_microsoft.powershell.psreadline_31bf3856ad364e35_10.0.17763.1_none_614e177b40342144\Microsoft.PowerShell.PSReadline.dll
2.0.0-beta3      2.0.0            C:\Program Files\PowerShell\6\Modules\PSReadLine\Microsoft.PowerShell.PSReadLine2.dll
2.0.0-beta3      2.0.0            C:\Users\steph\.vscode\extensions\ms-vscode.powershell-2.0.0-insiders-834\modules\PSReadLine\2.0.0\Microsoft.PowerShell.PSReadLine2.dll

  • as modules in pwsh 6.1
PS C:/Users/steph> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS C:/Users/steph> $env:PSModulePath -split ';' | % { ls -dir -filter PSReadline $_ -erroraction ignore } | % { ls -filter *.dll $_.FullName } | % { $_.VersionInfo }

ProductVersion   FileVersion      FileName
--------------   -----------      --------
2.0.0-beta3      2.0.0            C:\program files\powershell\6\Modules\PSReadLine\Microsoft.PowerShell.PSReadLine2.dll
  • as modules in Windows PowerShell 5.1 (console host, FWIW, I expect ISE to use the same)
PS C:/Users/steph> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:/Users/steph> $env:PSModulePath -split ';' | % { ls -dir -filter PSReadline $_ -erroraction ignore } | % { ls -filter *.dll $_.FullName } | % { $_.VersionInfo }
<no output>

sba923 avatar Oct 12 '18 05:10 sba923

With https://ci.appveyor.com/api/buildjobs/ma1a8og5h1d0g5cu/artifacts/PowerShell-insiders.vsix posted yesterday I still get the endless loop...

sba923 avatar Dec 01 '18 06:12 sba923

Just noticed that at my PS6 prompt I don't get syntax coloring, whereas it works in PS5.1 -- both with PSReadline 2.0.0-beta3. What's up, doc?

sba923 avatar Jan 22 '19 07:01 sba923

We'll have an official preview release this week that will be installable from the extension marketplace.

TylerLeonhardt avatar Jan 22 '19 08:01 TylerLeonhardt

@sba923 Is it PS6.0? If so try updating to 6.1

SeeminglyScience avatar Jan 22 '19 12:01 SeeminglyScience

I'm running 6.1.2 on all my systems

sba923 avatar Jan 22 '19 15:01 sba923