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

Terminal run selection using powershell should run selection as a block, not as individual lines #9715

Closed
gerane opened this issue Jul 25, 2016 · 12 comments
Assignees
Labels
terminal Integrated terminal issues windows VS Code on Windows issues
Milestone

Comments

@gerane
Copy link

gerane commented Jul 25, 2016

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

PS C:\>
>>
  • VSCode Version: 1.4.0-insiders 7/25, but has been around for several builds
  • OS Version: Windows 10

Steps to Reproduce:

  1. run selection in terminal on windows
@kieferrm kieferrm added the terminal Integrated terminal issues label Jul 26, 2016
@Tyriar Tyriar added the info-needed Issue requires more information from poster label Jul 26, 2016
@Tyriar
Copy link
Member

Tyriar commented Jul 26, 2016

The code is meant to run the selection and add an os.EOL if it doesn't end in one. Do you see any reason why Powershell would behave differently with this?

/cc @chrmarti

@Tyriar Tyriar added this to the August 2016 milestone Jul 26, 2016
@himanshub16
Copy link

I have similar issue. Pressing backspace adds a new line to the integrated terminal.
OS : Debian Stretch
VSCode : 1.3.1

@chrmarti
Copy link
Contributor

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

@gerane
Copy link
Author

gerane commented Aug 4, 2016

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

@Tyriar Tyriar added the windows VS Code on Windows issues label Aug 12, 2016
@Tyriar
Copy link
Member

Tyriar commented Aug 12, 2016

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 foreach is getting evaluated and { is waiting until it's closed. If you can put { at the end of the foreach I expect it to work.

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

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

@Tyriar Tyriar added help wanted Issues identified as good community contribution opportunities feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Aug 12, 2016
@Tyriar Tyriar modified the milestones: Backlog, August 2016 Aug 12, 2016
@Tyriar Tyriar changed the title Run Selection adds a new line to prompt Terminal run selection using powershell should run selection as a block, not as individual lines Aug 12, 2016
@Tyriar
Copy link
Member

Tyriar commented Aug 12, 2016

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 Tyriar removed the help wanted Issues identified as good community contribution opportunities label Aug 12, 2016
@gerane
Copy link
Author

gerane commented Sep 19, 2016

@Tyriar this would move back to using f8 for run selection similar to how it runs now, but in the open terminal correct?

@Tyriar
Copy link
Member

Tyriar commented Sep 19, 2016

F8 looks like it's bound to editor.action.marker.next?

@gerane
Copy link
Author

gerane commented Oct 13, 2016

@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'" }

@gerane
Copy link
Author

gerane commented Oct 13, 2016

This is likely also impacted by PSReadline #7077

@Tyriar
Copy link
Member

Tyriar commented Oct 13, 2016

I always assumed that the issues like this were related to the fact that pty.js that vscode uses to communicate with the terminal process has a dated version of winpty of which the support for powershell is limited.

@Tyriar
Copy link
Member

Tyriar commented Apr 20, 2017

Closing this as the situation has changed and the PowerShell experience is owned by https://github.com/PowerShell/vscode-powershell

@Tyriar Tyriar closed this as completed Apr 20, 2017
@Tyriar Tyriar removed the feature-request Request for new features or functionality label Apr 20, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
terminal Integrated terminal issues windows VS Code on Windows issues
Projects
None yet
Development

No branches or pull requests

5 participants