-
Notifications
You must be signed in to change notification settings - Fork 320
Fix System.ArgumentOutOfRangeException while get-tab #704
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
Conversation
|
It looks like It seems reasonable to fall back to this fix if the menu + the command line won't fit on the screen. Also - when selecting items from the menu, the tooltip is displayed below the menu. That should be disabled if it won't fit on the screen. |
|
Thank you @lzybkr for your comments. Could you please give me more detailed info when you say "it looks like MenuComplete is still a problem "? |
|
If you invoke Set-PSReadLineKeyBinding -Key Tab -Function MenuCompleteThen you will hit the call that tries to set the cursor position incorrectly. Your change avoids that call, but it is still reachable and many people do use |
|
For the cursor position issue while hit the Tab, we also need to apply the fix from https://github.com/PowerShell/PowerShell/pull/7299/files (the next release of pscore will contain it). Once applied the fix, invoking the MenuComplete should work fine. I tested it on Linux and CloudShell. I don't see the cursor issue. |
|
I don't think that's correct. I have your to PSReadLine and shouldn't need the fix to PowerShell (no Write-Progress calls). Try opening an instance of PowerShell, set the window height to 20, type Get-CCtrl+Space then use the arrow keys until After doing this, I see the same exception as the one you are trying to fix. |
PSReadLine/Completion.cs
Outdated
| else | ||
| { | ||
| // Start a new line to show the menu contents | ||
| console.Write("\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could write over some of the buffer if you press Tab anywhere that is not the last line, e.g.:
PS> & { Get-C<Tab><Tab>
>> }
After pressing Tab Tab, the screen might look like:
PS> & { Get-C<Tab><Tab>
Get-C1 Get-C2 Get-C3
PS> & { Get-C
>> }
When it should look like:
PS> & { Get-C<Tab><Tab>
>> }
Get-C1 Get-C2 Get-C3
PS> & { Get-C
>> }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jason, I submitted the fix and tested it. It seems working fine now. Please take a look it again. Thanks!
PSReadLine/Completion.cs
Outdated
| } | ||
| else | ||
| { | ||
| EnsureMenuAndInputIsVisible(console, tooltipLineCount: 0, rows:0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this call necessary? I suspected it wasn't and tested briefly with it removed, I didn't see any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. we needed it. On Windows, I do not see problem either. But on Linux the System.ArgumentOutOfRangeException occurs on the EnsureMenuAndInputIsVisible() , Singleton._initialY -= toScroll becomes negative when rows is large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jianyunt - after resolving this comment (either removing the call or confirming it is needed), I think this PR is ready to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lzybkr Yes we need to keep this Line https://github.com/lzybkr/PSReadLine/blob/2f57fe5091e0e0cd343b86851dc31c9bdcb2afd5/PSReadLine/Completion.cs#L501 to avoid the ArgumentOutOfRangeException exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you relying on the + 1 to write out a single newline?
Based on the comment in EnsureMenuAndInputIsVisible, I could see that + 1 being removed at some point, and then the method would do nothing, right?
If my understanding is correct, it would be good to have some way to ensure this problem doesn't come back if someone removes that + 1 - a test, or maybe pass rows:1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found calling EnsureMenuAndInputIsVisible can cause the ArgumentOutOfRangeException when the window is reduced to one line height or the following can cause the exception too when the window height is 5 in this case (full screen editing). Thus I changed back to use console.Write(), after console.SetCursorPosition(0, this.Top); . It seems work fine for all cases now. Thanks.
& {Get-C
abc1
abc2
abc3
}
PSReadLine/Completion.cs
Outdated
| } | ||
| else | ||
| { | ||
| // Update the cursor coordinates after showing the menu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this block necessary? InvokePrompt is called immediately after the call site that passes menuSelect: false and InvokePrompt is correctly updating these fields.
I tested briefly with these commented out and didn't see any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. We do not need it. I added it because I used Console.Write("\n") before. Removed it now. Thanks.
jianyunt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lzybkr Yes we need to keep this Line https://github.com/lzybkr/PSReadLine/blob/2f57fe5091e0e0cd343b86851dc31c9bdcb2afd5/PSReadLine/Completion.cs#L501 to avoid the ArgumentOutOfRangeException exception.
PSReadLine/Completion.cs
Outdated
| } | ||
| else | ||
| { | ||
| EnsureMenuAndInputIsVisible(console, tooltipLineCount: 0, rows:0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. we needed it. On Windows, I do not see problem either. But on Linux the System.ArgumentOutOfRangeException occurs on the EnsureMenuAndInputIsVisible() , Singleton._initialY -= toScroll becomes negative when rows is large.
PSReadLine/Completion.cs
Outdated
| } | ||
| else | ||
| { | ||
| // Update the cursor coordinates after showing the menu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. We do not need it. I added it because I used Console.Write("\n") before. Removed it now. Thanks.
In the #663, @gshacklett has commented get- and then tab PSReadLine will throw. This case is very often on cloudshell because Azure cmdlets are quite long and people use tab a lot.
The fix is to let contents display until complete for the menu not selected case. I tested on Windows, Linux and cloudshell, the fix seems to be working. Please code review. Thanks.
However I broke the PossibleCompletions() tests. The fix changed the parameter in calling InvokePrompt https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/Completion.cs#L736 so code path is different. With the fix, we are executing the else block in https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/ReadLine.cs#L942.