-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Terminal run selection using powershell should run selection as a block, not as individual lines #9715
Comments
The code is meant to run the selection and add an /cc @chrmarti |
I have similar issue. Pressing backspace adds a new line to the integrated terminal. |
@gerane Could you share the command you are running where this reproduces? Or is this with any command? (I couldn't reproduce so far.) @himanshub16 That sounds like a separate problem, could you open a new issue for that if it persists? Thanks. |
@chrisbenti it is every command. It runs each line individually unless in curly braces, which means I can't actually use it. For example, this is what is in my editor atm and just encountered this as we speak. $Combined = $JunkDomains + $Blocked | sort -unique
$NewBlocked = @()
foreach ($Item in $Combined)
{
if ($Ignored -notcontains $Item)
{
$NewBlocked += $Item
}
} and the output of using run selection PS C:\> $Combined = $JunkDomains + $Blocked | sort -unique
>>
PS C:\> $NewBlocked = @()
>>
PS C:\> foreach ($Item in $Combined)
>>
At line:1 char:29
+ foreach ($Item in $Combined)
+ ~
Missing statement body in foreach loop.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingForeachStatement
PS C:\>
PS C:\> {
>> if ($Ignored -notcontains $Item)
>> {
>> $NewBlocked += $Item
>> }
>> }
>>
>>
>>
>>
>>
>>
if ($Ignored -notcontains $Item)
{
$NewBlocked += $Item
}
PS C:\> The output is incredibly odd. I selected exactly the text above, no added lines or spaces when I ran selection. This also occurs if I run powershell with -NoProfile so its not something from my profile. |
OK so I think I know what is happening here. The block of text is not send to the terminal, instead each character is send, meaning that each line is evaluated unless Powershell thinks it's a multi-line statement. That's why This is how I would expect this to work for bash. So I suspect you want to run the selection as a since block, which would mean maybe wrapping it in some Powershell exec command. Perhaps Let me know if this makes sense, going to open this up for PRs/help if so. The function that this would need to be handled in is https://github.com/Microsoft/vscode/blob/7f15980aaa768b05e10f09bc42dbb29a22c8b7dc/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts#L120. There's an issue with this though in that it would need to confirm that powershell is in the active terminal instance/process which may be difficult to determine for the same reason the title of the terminal switcher dropdown doesn't change on Windows. As such maybe it can only work when the shell is explicitly set to powershell (meaning it wouldn't work in cmd shells that launch powershell or powershell wrapped in a script). |
Alternatively due to the issues with detecting the shell on Windows, maybe this is better left to the powershell extension once #9957 is implemented and it integrates with the terminal? |
@Tyriar this would move back to using f8 for run selection similar to how it runs now, but in the open terminal correct? |
F8 looks like it's bound to |
@Tyriar the powershell extension sets f8 to run selection. I wanted to update after trying @daviwil sort of beta version of the powershell extension that integrates into the terminal. It appears some of the odd run selection behavior is being caused by the built in PowerShell module called PSReadline. Since PowerShell v4 it is auto loaded at Powershell startup in consoles. It is what provides many of the highlighting and and keyboard shortcuts that give a much improved PowerShell experience. In the PowerShell Extension David is having to remove the PSReadline module because it is interfering with how he is having to communicate with the terminal. I believe this is temporary and he is looking into a solution for this, but when testing this I tested the Run Selection to see if it impacted anything. Many of the issues went away, but there were still a few present. Mainly with added lines at the end and I think if there was a space between 2 code blocks it would run those as 2 different entries. It got me thinking that maybe PSReadline could be causing some other issues, and was wanting to bring it up and maybe see if we can figure out what is going on and see if there is a way we can improve this. EDIT: here is what the PowerShell Extension sets as a keybinding { "key": "f8", "command": "PowerShell.RunSelection",
"when": "editorTextFocus && editorLangId == 'powershell'" } |
This is likely also impacted by PSReadline #7077 |
Closing this as the situation has changed and the PowerShell experience is owned by https://github.com/PowerShell/vscode-powershell |
When running text selection in the integrated terminal, when it finishes and goes back to the prompt it is adding a new line. You have to backspace back up.
Before
PS C:\>
After
Steps to Reproduce:
The text was updated successfully, but these errors were encountered: