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

Enable PSReadline support in the integrated console (syntax highlighting, keyboard navigation)

Open daviwil opened this issue 9 years ago • 133 comments

PSReadline is not supported in the integrated console at this time. A non-trivial amount of work is needed to make PowerShell Editor Services and PSReadline play nicely together so this could take some time.

Features this will enable:

  • Ctrl+Arrow keys, etc (keyboard navigation of the input line)
  • Syntax highlighting of input text
  • Multi-line text input (writing a function definition in the console across multiple lines)

daviwil avatar Mar 14 '17 14:03 daviwil

Just FYI everyone, we've checked and respun the builds to make sure no event-stream stuff is in them now. I would recommend changing over to the new builds.

We're working on sorting out a couple of issues in the latest 1.x release before investing the time in rebasing 2.0.0, but it will happen soon.

There is one last major issue we're working through to make PSReadLine support viable, involving prompt cancellation -- so we want to fix that before we create a proper release channel. We're working on it, but @TylerLeonhardt and I are currently juggling some other stuff at the minute (I am porting Windows PowerShell modules to work with PowerShell Core, for example). Anyway, we're very conscious of all of it, we just want to make sure that when we release it's something that will be reliable and useful.

rjmholt avatar Dec 06 '18 21:12 rjmholt

When can we hope to get the "endless loop" problem fixed? This is a showstopper for moving from ISE to VScode…

sba923 avatar Dec 14 '18 05:12 sba923

Btw, this also blocks the fix for this issue that is fixed in PSReadLine but still appears in the integrated console: https://github.com/PowerShell/PowerShell/issues/5983

felixfbecker avatar Dec 17 '18 14:12 felixfbecker

Any status update on this?

JakeShirley avatar Feb 01 '19 02:02 JakeShirley

You can try this feature via the preview version of the extension. See https://blogs.msdn.microsoft.com/powershell/2019/01/23/announcing-the-powershell-preview-extension-in-vscode/

rkeithhill avatar Feb 01 '19 03:02 rkeithhill

Tried it, it's still unusable due to the "endless prompting loop" issue (which you said you encountered too at https://github.com/PowerShell/vscode-powershell/issues/1570#issuecomment-457621468)!

What could I do to help fix that?

sba923 avatar Feb 01 '19 05:02 sba923

@sba923 You're the only one complaining about an "endless loop" issue for which you've been prompted for further diagnostic information. I suggest opening an issue if you actually have a problem instead of detracting from this 2.0 discussion.

morsley avatar Feb 04 '19 19:02 morsley

I'm not the only one, see @rkeithhill's comment on the existing issue for that exact "endless loop" problem. This is related to non-US keyboard layouts, and just makes version 2.0 of the PowerShell extension for VScode plainly unusable if you happen to have such a keyboard.

sba923 avatar Feb 04 '19 20:02 sba923

Why does the Integrated Console even have to be visible? Why not start a PowerShell instance in the background for error-checking, etc.?

doxxx avatar Feb 12 '19 18:02 doxxx

@doxxx - It doesn't. You can uncheck PowerShell > Integrated Console: Show On Startup in your Code settings to not show it if you prefer it not to show. This should still allow the language server to start so you get the rest of the features that come with that (i.e. error checking).

scrthq avatar Feb 12 '19 18:02 scrthq

@scrthq I do have that disabled. The problem, however, is that when I press the Terminal: Focus Terminal shortcut, it shows me the PowerShell Integrated Console. IMO, it shouldn't even appear in the list of terminals if that option is disabled.

doxxx avatar Feb 13 '19 18:02 doxxx

The problem with that is that the PowerShell Integrated Console holds the PowerShell session that is used to give all the editor features - intellisense, codelens, etc.

This was done to give an experience similar to that of the ISE (editor up top, console on the bottom) - something that a lot of users had to have to adopt the PowerShell extension.

Short of major architectural change, what you're asking for is not going to be possible, I'm afraid.

Maybe someone could take PowerShell Editor Services which is the backend to the PowerShell extension and leverage the -Stdio flag to create a "PowerShell lite" extension that does more what you're looking for... but it's probably not something we can address in the short term at least.

TylerLeonhardt avatar Feb 14 '19 03:02 TylerLeonhardt

I hadn't realized that replicating the experience of the PowerShell ISE was the goal of the extension. That explains a lot. :)

doxxx avatar Feb 14 '19 14:02 doxxx

I just tried the PowerShell Preview extension with the PSReadLine support enabled. Everything appears to be working correctly! Thanks so much for this!

doxxx avatar Feb 14 '19 15:02 doxxx

Is Ctrl+Backspace supposed to be working with PSReadLine support in the latest preview build?

GlitterHorn avatar Feb 17 '19 23:02 GlitterHorn

Try putting this in your VSCode specific profile - (Microsoft.VSCode_profile.ps1):

Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord 'Alt+D' -Function KillWord
Set-PSReadLineKeyHandler -Chord 'Ctrl+@' -Function MenuComplete

rkeithhill avatar Feb 18 '19 00:02 rkeithhill

Try putting this in your VSCode specific profile - (Microsoft.VSCode_profile.ps1):

Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord 'Alt+D' -Function KillWord
Set-PSReadLineKeyHandler -Chord 'Ctrl+@' -Function MenuComplete

Thanks - I had to put this in Microsoft.PowerShell_profile.ps1, but it worked!

$profile is set to that file according to VSCode's terminal.

GlitterHorn avatar Feb 18 '19 00:02 GlitterHorn

Sorry, I thought you were trying out the PSRL support in the PowerShell Integrated Console which does load the VSCode profile. The profile you put this in will load in both the PSIC and the regular integrated terminal. But it will also load this into any PowerShell console. You might want to fire up a PowerShell console and make sure backspace still works as you expect.

rkeithhill avatar Feb 18 '19 00:02 rkeithhill

I have ConPTY set up with the VSCode extension, if that makes any difference. I changed that after seeing somewhere (github issue, probably) that I should use ConPTY to have keyboard shortcuts like this.

GlitterHorn avatar Feb 18 '19 00:02 GlitterHorn

Cool. Well if you wind up with issues in the external PowerShell console, you could conditionally invoke the above script like so:

if ($env:TERM_PROGRAM -eq "vscode") {
    Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
    Set-PSReadLineKeyHandler -Chord 'Alt+D' -Function KillWord
    Set-PSReadLineKeyHandler -Chord 'Ctrl+@' -Function MenuComplete    
}

There is also a $env:TERM_PROGRAM_VERSION that might come in handy.

rkeithhill avatar Feb 18 '19 01:02 rkeithhill