vscode-powershell: ArgumentOutOfRangeException in Integrated Console when entering long input lines that wrap
– EDIT FROM THE MAINTAINERS –
The PowerShell Preview extension has PSReadLine support and should resolve this issue. If you’re experiencing this, please give the preview extension a try. We’ve committed to delivering this fix in the stable extension release in January 2020.
– ORIGINAL ISSUE –
An error occurred while reading input:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was 3000.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.EditorServices.Console.ConsoleReadLine.InsertInput(StringBuilder inputLine, Int32 promptStartCol, Int32 promptStartRow, String inser
tedInput, Int32 cursorIndex, Int32 insertIndex, Int32 replaceLength, Int32 finalCursorIndex)
at Microsoft.PowerShell.EditorServices.Console.ConsoleReadLine.<ReadLine>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerShell.EditorServices.Console.ConsoleService.<StartReplLoop>d__21.MoveNext()
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 27
- Comments: 65 (17 by maintainers)
@skeeler due to .NET Core 3.0 overhauling their Console APIs, we are going to wait til after PowerShell 7 GA ships to move what is in preview into stable.
The next preview will contain a huge refactor of the codebase that includes some perf/stability fixes. We will then address outstanding issues at that point until 7 is released.
Just chiming in a little in case y’all might want to let the fix slip. Still impacted by this right now, and rather missing Powershell ISE.
the preview version is quite good , i haven’t encountered this issue yet in the new extension
@TylerLeonhardt I confirm this doesn’t happen with the Preview extension. Thank you!
@mabaumebad, have you tried the insiders extension? It uses PSReadLine, though there are still some issues with PSReadLine support, there is a PR there https://github.com/PowerShell/PSReadLine/pull/979 that seems to take care of the ArgumentOutOfRangeExceptions that are similar to this issue.
@BenJTucker FYI, launching a PowerShell subprocess will mean changes you make in that subprocess are not “integrated”; modules you import and functions, variables, etc that you define in that subprocess won’t be picked up by VSCode.
Since PSReadLine does a much better job of handling the finicky business of terminal buffers, we’re focusing on enabling that. It’s currently available on Windows in the
powershell-previewextension@clmcgrath The new terminal is mainly built using C++ and a completely different UI stack. VS-Code is based on typescript/electron, which is completely different, one cannot just embed the new terminal.
Closing as PSReadLine is now available in the PowerShell Preview extension, which resolves this issue, tracking that PSReadLine is not available in the main PowerShell Extension here #1793
@Goblenus your screenshot is of the PowerShell Stable extension. You want the “PowerShell Preview” extension. It’s in the extension marketplace as well.
Yeah, the problem is that you can’t depend on your application to be the only thing that sets cursor position. In this case it looks like something (maybe us, maybe PSReadLine) is also setting cursor position, probably to
0, 0. So if you try to set the cursor position to0 - 1, that’s the expected error message.You could either validate cursor position before trying to set it, or do something like
Console.SetCursorPosition(0, Math.Max(0, Console.CursorTop - 1)).Hi Guys,
with the Insider Extension the Problem seems to be gone. Thank you!
🔜
… but seriously. This won’t be in the next release next week 1.6.0… however, we’re targeting it to be released in 1.7.0.
@SeeminglyScience has been working (tirelessly, I might add) on adding PSReadLine support. He’s made some incredible progress. This issue will be fixed when that work is done.
Looks like this only happens when the output exceeds the Console.BufferHeight and the user types a line longer than the Console.WindowWidth. PSReadline solves this problem by scrolling the buffer:
https://github.com/lzybkr/PSReadLine/blob/8e851bfadbbe7cd5d898b2f01eb6cf010f684a71/PSReadLine/Render.cs#L473
The cross-platform implementation of ScrollBuffer is here:
https://github.com/PowerShell/PowerShell/blob/7a55bf98b2370ab4817ab2533cb67673053ee446/src/Microsoft.PowerShell.PSReadLine/ConsoleLib.cs#L1055
I’ll implement the fix for this in June since it isn’t a critical issue and only shows up in specific cases. Let me know if it is a big annoyance and I’ll prioritize it sooner!