PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.72k stars 495 forks source link

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

Closed daviwil closed 5 years ago

daviwil commented 7 years ago

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:

dotps1 commented 7 years ago

i was going to request this yesterday but i got distracted.

cobdev commented 7 years ago

Thank you!

Liquidmantis commented 7 years ago

Hopefully this will include PSReadline's Vi EditMode and ViModeIndicator. I found this issue while searching for a way to get vi mode working.

gwojan commented 7 years ago

Um, @daviwil, when did PSReadline start working in the VSCode PowerShell terminal window? I just opened the terminal and noticed my PSReadline history was available. A quick Set-PSReadlineOption -EditMode Vi and I'm in hog heaven!

Is there something I should be watching for? I guess I should mention: Windows 10 Anniversary Update, PowerShell 5.1, VSCode 1.13.1, PowerShell addin 1.4.1...

rkeithhill commented 7 years ago

PSReadline support in the PowerShell terminal is a VSCode feature. What isn't implemented yet is PSReadline support in the PowerShell Integrated Console.

daviwil commented 7 years ago

Hey Greg, unfortunately you're just seeing PSReadLine work inside of plain powershell.exe in the integrated terminal. As Keith mentions, it doesn't currently work in the PowerShell Integrated Console yet. I've started working on that last week though so I expect to have some progress soon!

gwojan commented 7 years ago

Thanks @daviwil and @rkeithhill! I guess I need to start playing with the Integrated Console because I'm sure I knew it was there. It will be great to have PSReadline support because that one particular feature is why I abandoned the ISE a long time ago. I'm such a lousy typist I need all the help I can get. ;-)

DarkLite1 commented 7 years ago

@daviwil any update on this killer feature? ;)

1trevor commented 7 years ago

Will this also make it so Clear-Host actually clears the terminal window and doesn't just move the input line to the top of the screen?

djobin commented 7 years ago

Hi!! @daviwil,

Any update on this enhancement ? It sure is one of the few things that keeps me going back to ISE or the powershell console from time to time.

On a sidenote... I really hope this great project is not put on hold.. cause it seems that there's less and less activity in the repo.

Thanks for all the work!

DarkLite1 commented 7 years ago

@djobin agree, see #31555

moymike commented 6 years ago

Just adding a 'me too'.

As far as I can tell, this is the feature needed to allow for shelving of ISE for VScode. I love the GIT integration in VScode, but the crippled debug is a show stopper.

I'm guessing that the PSReadLine support may fix the $host.PrivateData issue also? (it contains terminal color values, just not in the integrated console)

SeeminglyScience commented 6 years ago

It's coming. Still some kinks left, but it's coming.

PSReadLine

I'm guessing that the PSReadLine support may fix the $host.PrivateData issue also? (it contains terminal color values, just not in the integrated console)

Definitely not related. I didn't get a chance to look at it this weekend but we'll get it fixed for sure :)

TylerLeonhardt commented 6 years ago

omg that looks awesome @SeeminglyScience, I'm so pumped 🎉

ghost commented 6 years ago

Looks great @SeeminglyScience! I'm ready to ditch ISE :)

rfletche847 commented 6 years ago

Found this while trying to get syntax highlighting working in the integrated console. I look forward to this being available! Great work!

Liquidmantis commented 6 years ago

@SeeminglyScience Any ETA for seeing this in Insiders? This is the final piece to having a comfortable single pane workflow and not need to set up a side-by-side ConEmu instance.

Thanks for the work!

SeeminglyScience commented 6 years ago

@Liquidmantis I'm thinking I can get a solid build of it behind a feature flag not next release but the one after. No promises as I'm a little short on free time atm, but that's the goal :)

vrdse commented 6 years ago

@SeeminglyScience that's great to hear! can't wait to finally have PSReadline support, thanks

darkquake93 commented 6 years ago

I got it working, all you do is import the module ;) Read the install instructions for PowerShellGallery, it's fairly straightforward.

https://github.com/lzybkr/PSReadLine

daviwil commented 6 years ago

@darkquake93 if you just import the standard PSReadline module into the PS extension's Integrated Console, it will break all language and debugging functionality. @SeeminglyScience's work is to enable PSReadline to coexist with the PowerShell extension's language capabilities.

darkquake93 commented 6 years ago

Oh I didn't realise. I only use Powershell for minimal use on my home Windows 7 machine, and all seems good for the time being with syntax highlighting and ctrl+delete etc working. I'll keep that in mind though, but my computer at work is already on Windows 10 so that's probably where I'll do debugging in the future, I just like to run simple scripts at home :)

rddoove commented 6 years ago

When o When will this be there?

rkeithhill commented 6 years ago

https://www.youtube.com/watch?v=39S3dLDEbYs :-)

darkquake93 commented 6 years ago

You're welcome to try installing the module anyway like I did, I found it was good enough.

SeeminglyScience commented 6 years ago

@darkquake93 It sounds like you are talking about getting PSReadLine to work in Windows 7, this discussion is for getting PSReadLine to work within the console created by this extension in VSCode. We explicitly remove the module at start up because it breaks all editor features, just installing the module wouldn't make a difference in this case.

darkquake93 commented 6 years ago

Oh sorry, you're right. Thanks for the explanation anyway.

codykonior commented 6 years ago

Any update on when this will be available?

jtuttas commented 6 years ago

Any news about this feature?

TylerLeonhardt commented 6 years ago

@SeeminglyScience is working really hard on this. We had a demo at the MVP Summit in March but it still has a few bugs he is figuring out. It's a substantial change to PowerShell Editor Services.

Liquidmantis commented 6 years ago

:shipit:

uttampcu commented 6 years ago

Not sure if it's the same core problem, but when hitting F8 on a line of code, focus changes to the integrated console instead of the code, which is different from powershell_ise behavior. I prefer the powershell_ise behavior, not sure how many others do. (Answered below by tylerl0706 - thx)

TylerLeonhardt commented 6 years ago

@uttampcu you're going to want to set the powershell.integratedConsole.focusConsoleOnExecute setting. That will do what you want. It behaves the way it does in order to be accessible.

uttampcu commented 6 years ago

Any workarounds available for Issue #535 while we wait? Can we get @SeeminglyScience 's pre-release code to reduce the pain?

artisticcheese commented 6 years ago

Is inability to press arrow up/down to go previous/last command issued during debugging is part of this issue?

TylerLeonhardt commented 6 years ago

@artisticcheese that will also be fixed with PSReadLine

chrisjeter commented 6 years ago

Looking forward to this update also!

rjmholt commented 6 years ago

I believe our integration with PSReadLine depends on a PSReadLine 2 API, which is incompatible with PowerShell versions below v5. So before we can bring PSReadLine in, we will need to resolve our support story for PowerShell v4 and below.

Please see here: https://github.com/PowerShell/vscode-powershell/issues/1310

Stephanevg commented 6 years ago

To me, this sounds like this will last a long time before we get this available. I opened an issue back in August 2017 (https://github.com/PowerShell/vscode-powershell/issues/975 ) mentionning the fact that history and up and down arrow keys don't work. I got told it would be fixed with the introduction of PSreadLine.

As matter a fact, according to https://github.com/PowerShell/vscode-powershell/issues/1310 mentionned above, you want to drop the support for powershell v3, v4. Which means that the original issue (that a lot of people seem to be asking for) won't be fixed when working on scripts on older versions of powershell.

To me, this is a crucial functionality for any IDE, which really enhance the user experience. I think everybody has waited pretty long for this fix. This drives me nuts sometimes, and I was actually really looking forward to it.

SeeminglyScience commented 6 years ago

@Stephanevg I understand your frustration but that issue in particular is more complicated than it probably appears. I looked into this awhile ago and the fix is actually pretty easy, but it's currently hiding a bigger issue.

Right now when you run a command through the debugger there is no way to suppress it from history. This includes all of the commands we run in the background to get variables, the call stack, intellisense, everything. A lot of those commands get invoked every single time a command is ran from the prompt and/or every time the debugger steps. So currently, if you could navigate history, you'd be looking at mostly the background commands.

Keep in mind this is a PowerShell API, so the older versions are pretty much set in stone. Usually we can find some sort of workaround to kind of fake the same functionality, but this one is pretty solidly hard coded in.

PSReadLine solves this in a way because it has it's own history management system. But getting that working with the other editor features requires changes to PSReadLine. Older versions of PSReadLine support PSv3/4 but the newest one (the one we have to add these changes to) does not.

All that said remember you can still write scripts targeting v3/4, you only need PSv5.1 installed on your dev machine. For example, if you are currently writing scripts that target PSv2 then nothing will change because we already don't support that version.

dbaileyut commented 6 years ago

Getting closer! https://github.com/PowerShell/PowerShellEditorServices/pull/672

BatmanAMA commented 6 years ago

It looks like that PR has been merged into 2.0.0 - What is left to get it working with this extension in insiders? Is there anything that could use love to get this closer to reality?

TylerLeonhardt commented 6 years ago

@BatmanAMA @rjmholt is working on migrating PowerShell Editor Services to .NET Standard 2.0 and PowerShell Standard.

https://github.com/PowerShell/PowerShellEditorServices/pull/741

rjmholt commented 6 years ago

Here's a build from that latest PR (which is pretty much complete) with the PSReadLine features enabled: psvsix.zip

(GitHub won't let me upload a VSIX directly, but just expand the zip and it will be in there)

To install:

code --install-extension ./PowerShell-v2-insiders.vsix

Or if you use VSCode Insiders:

code-insiders --install-extension ./PowerShell-v2-insiders.vsix

Then you will need to enable the feature in your VSCode user settings by adding to the feature flags:

{
    "powershell.developer.featureFlags": [
        "PSReadLine"
    ]
}

There are still come trickier bugs, mainly on *nix.

If you're interested in the source, the backend can be built from this branch (I made a new one where the PSRL import is hardcoded, since the newest PowerShell Core overrides our PSRL with one that has the same version but is older -- we're waiting on the next PSRL release to fix that). The frontend is based on this branch (which is just the normal frontend with the versions changed to make installation nicer), but needs these lines removed.

Anyway, give it a try and let us know how it goes.

raandree commented 6 years ago

Right after having the new version installed, debugging was no longer possible:

Cannot debug or run a PowerShell script until the PowerShell session has started. Wait for the PowerShell session to finish starting and try again.

After some time, I get this error:

The language service could not be started: 

The log shows:

9/6/2018 1:29:01 PM [NORMAL] - Visual Studio Code v1.26.1 64-bit
9/6/2018 1:29:01 PM [NORMAL] - PowerShell Extension v2.0.0
9/6/2018 1:29:01 PM [NORMAL] - Operating System: Windows 64-bit
9/6/2018 1:29:01 PM [NORMAL] - Path specified by 'powerShellExePath' setting - '' - not found, reverting to default PowerShell path.
9/6/2018 1:29:01 PM [NORMAL] - Language server starting --
9/6/2018 1:29:01 PM [NORMAL] -     exe: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
9/6/2018 1:29:01 PM [NORMAL] -     args: C:\Users\randr\.vscode\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\Start-EditorServices.ps1 -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2.0.0'-AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\randr\.vscode\extensions\ms-vscode.powershell-2.0.0\modules'-EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\randr\.vscode\extensions\ms-vscode.powershell-2.0.0\logs\1536233341-15e829a8-2222-4bfd-8dd7-003ff46574671536233335047\EditorServices.log' -SessionDetailsPath 'C:\Users\randr\.vscode\extensions\ms-vscode.powershell-2.0.0\sessions\PSES-VSCode-19296-915042' -FeatureFlags @('PSReadLine')
9/6/2018 1:29:01 PM [NORMAL] - Syntax Folding Provider registered
9/6/2018 1:29:02 PM [NORMAL] - powershell.exe started, pid: 5920
9/6/2018 1:31:01 PM [NORMAL] - Language server startup failed.
9/6/2018 1:31:01 PM [ERROR] - The language service could not be started: 
9/6/2018 1:31:01 PM [ERROR] - Timed out waiting for session file to appear.
SeeminglyScience commented 6 years ago

@raandree This is a shot in the dark, but what's the highest .NET Framework version you have installed? If it's under 4.7.1, try installing that.

djobin commented 6 years ago

@raandree I have the same issue and I have found that the Microsoft.PowerShell.EditorServices.dll library is not in the expected path when the 'Start-EditorServices.ps1' script runs.

from the PowerShellEditorServices.psm1 ::

if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") { Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.dll" Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.Host.dll" } else { Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.dll" Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Protocol.dll" Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Host.dll" }

On my system, I don't have Powershell 6 installed, only the Desktop version (5.1) and in the .\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin folder, there is only a 'Core' folder, no 'Desktop' folder.

It seems to me that this would only work with Powershell Core installed.

TylerLeonhardt commented 6 years ago

@rjmholt has been working on porting all of PowerShell Editor Services to .NET Standard and this seems to be a place he missed.

Windows PowerShell 5.1 will be supported.

raandree commented 6 years ago

@SeeminglyScience, thanks for the hint, but .net 4.7.2 is installed.

PS C:\> Get-DotNetFrameworkVersion

ComputerName  Build Version        Comment
------------  ----- -------        -------
RAANDREE1     50727 2.0.50727.4927
RAANDREE1     30729 3.0.30729.4926
RAANDREE1     30729 3.5.30729.4926
RAANDREE1    461808 4.7.2          (Windows 10 1803)

@djobin, this is it. Missing the Desktop folder as well.

When do we get a new build to play with?

rjmholt commented 6 years ago

@raandree Just finishing one up now (sorry, currently in an Australian timezone, so a bit out of kilter with US business hours)