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

@rjmholt, thanks for the new version, this is a real improvement. Two things that I am missing:

  1. CTRL+Backspace does not delete the word left to the cursor but results in ^W.
  2. Clear-Screen still does not really clear the screen
  3. When killing the terminal using the recycle bin icon you will be asked if you want to restart it. If I click on yes, the terminal is created in the background but not shown. I have to create another terminal (Terminal -> New Terminal), kill the 2nd one to finally see the 1st one. This does not seem to be related to 2.0 of the PowerShell extension. I have this behavior since a week or two.
  4. Rich copy from the terminal would be very nice.

raandree avatar Sep 15 '18 09:09 raandree

Set the following PSRL handlers in your VSCode specific profile:

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

I'm assuming you're using the default Windows EditMode. If you use something else (Vi/Emacs) you may want other mappings.

rkeithhill avatar Sep 15 '18 16:09 rkeithhill

Clear-Screen still does not really clear the screen

This is an issue with VSCode and not the PS extension (or the PSRL integration). See https://github.com/Microsoft/vscode/issues/30638 and https://github.com/Microsoft/vscode/issues/45693

rkeithhill avatar Sep 15 '18 18:09 rkeithhill

I hate to say, but I can't get that latest test build to install...

I've uninstalled v1.9.0 of the extension, and then run:

"c:\Program Files\Microsoft VS Code\Code.exe" --install-extension d:\tmp\Powershell-v2-extremely-alpha.vsix

from a CMD prompt.

VScode starts up, but the extension isn't installed.

What am I missing?

sba923 avatar Oct 02 '18 19:10 sba923

If you try the same with a --verbose flag, that should provide more information to work with

rjmholt avatar Oct 02 '18 19:10 rjmholt

@sba923 that exe just launches code, the CLI arguments don't work with it. Try this:

& "C:\Program Files\Microsoft VS Code\bin\code.cmd" --install-extension D:\tmp\Powershell-v2-extremely-alpha.vsix

SeeminglyScience avatar Oct 02 '18 20:10 SeeminglyScience

Ah I didn't catch the .exe ending there (I remember it briefly giving me pause, but I dismissed it), nice one @SeeminglyScience!

rjmholt avatar Oct 02 '18 20:10 rjmholt

Tada!

PS D:/tmp> & 'C:\Program Files\Microsoft VS Code\bin\Code.cmd' --install-extension .\Powershell-v2-extremely-alpha.vsix
Code.cmd : [createInstance] extensionManagementService depends on downloadService which is NOT registered.
At line:1 char:1
+ & 'C:\Program Files\Microsoft VS Code\bin\Code.cmd' --install-extensi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ([createInstance...NOT registered.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Extension 'Powershell-v2-extremely-alpha.vsix' was successfully installed!

After that, starting VScode gets me something unusable ;-(

The Terminal pane starts a PowerShell, which shows the prompt repeatedly in an endless loop, like if I was holding the Enter key down for it to autorepeat...

sba923 avatar Oct 02 '18 20:10 sba923

Ah I've seen that before at some point. I think rather than trying to debug that, hold tight for a couple of days and we should have an AppVeyor asset to point to by then

rjmholt avatar Oct 02 '18 21:10 rjmholt

Ok, I've built a new one while doing some testing, so thought I should upload it here: psvsix.zip

All the links above also point to this one now.

This one is rebased on all the stability and performance work done in v1.9.0. As always, let me know if there are any issues.

rjmholt avatar Oct 02 '18 23:10 rjmholt

Thank you for the great work on this. For me, it was the only thing holding the extension back.

I've been testing for the last hour and I cannot get the Killword function to work with "Ctrl+Delete". Instead, I just get a "D" character.

Set-PSReadlineKeyHandler -Chord "Ctrl+Delete" -Function KillWord

If I change it to "Ctrl+D" it works. I've also enable the flag in my config.

Thank you again, this is fantastic.

GaryChan1 avatar Oct 03 '18 01:10 GaryChan1

@GaryChan1 Did you try this:

Set-PSReadLineKeyHandler -Chord 'Alt+D' -Function KillWord

See my previous comment

rkeithhill avatar Oct 03 '18 01:10 rkeithhill

Perhaps someone can point me in the right direction. I am running Code Insiders

Version: 1.28.0-insider (system setup)
Commit: 85d970acdee48f6dcecf909a0faeb3c6882217a9
Date: 2018-10-02T22:27:52.997Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Installed the vsix file with: code-insiders --install-extension C:\Users\xxxxx\Downloads\Powershell-v2-extremely-alpha.vsix

I also put in...

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

And opened VSCode and it thinks for a moment and then displays the following in the terminal pane:

An error occurred while starting PowerShell Editor Services:

Could not load file or assembly 'System.Security.AccessControl, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath,
ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblies(IEnumerable`1 assemblies)
   at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()
   at System.Management.Automation.Cmdlet.DoEndProcessing()
   at System.Management.Automation.CommandProcessorBase.Complete()

It then gives me the opportunity to see another log which displays this:

10/2/2018 8:29:37 PM [NORMAL] - Visual Studio Code v1.28.0-insider 64-bit
10/2/2018 8:29:37 PM [NORMAL] - PowerShell Extension v2.0.0
10/2/2018 8:29:37 PM [NORMAL] - Operating System: Windows 64-bit
10/2/2018 8:29:37 PM [NORMAL] - Language server starting --
10/2/2018 8:29:37 PM [NORMAL] -     exe: C:\Program Files\PowerShell\6.0.2\pwsh.exe
10/2/2018 8:29:37 PM [NORMAL] -     args: C:\Users\XXXXX\.vscode-insiders\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\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\logs\1538530177-70a76287-30ba-4526-bb28-9041ee5121c11538530173284\EditorServices.log' -SessionDetailsPath 'C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\sessions\PSES-VSCode-10260-653975' -FeatureFlags @()
10/2/2018 8:29:37 PM [NORMAL] - Syntax Folding Provider registered
10/2/2018 8:29:40 PM [NORMAL] - powershell.exe started, pid: 4344
10/2/2018 8:31:35 PM [NORMAL] - Language server startup failed.
10/2/2018 8:31:35 PM [ERROR] - The language service could not be started: 
10/2/2018 8:31:35 PM [ERROR] - Timed out waiting for session file to appear.

Also I did also try Run As Administrator on VSCode and got the same error.

I am sure it is something simple I didn't set up correctly ;-)

scotthardwick avatar Oct 03 '18 01:10 scotthardwick

@scotthardwick What version of .NET do you have installed? If you don't have at least 4.7.1, give that an update and see if that fixes it

SeeminglyScience avatar Oct 03 '18 01:10 SeeminglyScience

@rkeithhill That did it, thank you.

GaryChan1 avatar Oct 03 '18 02:10 GaryChan1

@scotthardwick can you also provide the output of:

$PSVersionTable

and

gci ~/.vscode-insiders/extensions/ms-vscode.powershell-2.0.0/modules/PowerShellEditorServices/bin/* -Recurse

rjmholt avatar Oct 03 '18 02:10 rjmholt

@SeeminglyScience and @rjmholt I have fiddled around some more and updated from Powershell 6.0.2 to 6.1.0 and now it works! I guess I didn't realize there was a minimum required spec there. Thanks for answering, it got me poking around at versions!

scotthardwick avatar Oct 03 '18 02:10 scotthardwick

Hmmmm, it ought to work with 6.0.x — I specifically tested that scenario (because it works differently to 6.1.x in terms of those Windows dependencies).

Can you provide the output of the above commands?

rjmholt avatar Oct 03 '18 02:10 rjmholt

I have already installed 6.1 so not sure if this is still useful, but here it is!

With "powershell.powerShellExePath": "C:\Program Files\PowerShell\6\pwsh.exe",

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

gci ~/.vscode-insiders/extensions/ms-vscode.powershell-2.0.0/modules/PowerShellEditorServices/bin/* -Recurse

Directory: C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/2/2018   8:28 PM                6.0
d-----        10/2/2018   8:28 PM                Desktop
-a----        10/2/2018   8:28 PM           9052 libdisablekeyecho.dylib
-a----        10/2/2018   8:28 PM           8840 libdisablekeyecho.so
-a----        10/2/2018   8:28 PM         396800 Microsoft.PowerShell.EditorServices.dll
-a----        10/2/2018   8:28 PM          35328 Microsoft.PowerShell.EditorServices.Host.dll
-a----        10/2/2018   8:28 PM           8572 Microsoft.PowerShell.EditorServices.Host.pdb
-a----        10/2/2018   8:28 PM         129100 Microsoft.PowerShell.EditorServices.pdb
-a----        10/2/2018   8:28 PM         252416 Microsoft.PowerShell.EditorServices.Protocol.dll
-a----        10/2/2018   8:28 PM          69612 Microsoft.PowerShell.EditorServices.Protocol.pdb
-a----        10/2/2018   8:28 PM         639488 Newtonsoft.Json.dll
-a----        10/2/2018   8:28 PM         118272 Serilog.dll
-a----        10/2/2018   8:28 PM           8704 Serilog.Sinks.Async.dll
-a----        10/2/2018   8:28 PM          31744 Serilog.Sinks.Console.dll
-a----        10/2/2018   8:28 PM          26624 Serilog.Sinks.File.dll
-a----        10/2/2018   8:28 PM           4096 UnixConsoleEcho.dll


    Directory:
    C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin\6.0


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/2/2018   8:28 PM          29840 System.IO.Pipes.AccessControl.dll
-a----        10/2/2018   8:28 PM         104584 System.Security.AccessControl.dll
-a----        10/2/2018   8:28 PM          82576 System.Security.Principal.Windows.dll


    Directory:
    C:\Users\XXXXX\.vscode-insiders\extensions\ms-vscode.powershell-2.0.0\modules\PowerShellEditorServices\bin\Desktop


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        10/2/2018   8:28 PM          25744 System.IO.Pipes.AccessControl.dll
-a----        10/2/2018   8:28 PM          39048 System.Security.AccessControl.dll
-a----        10/2/2018   8:28 PM          23688 System.Security.Principal.Windows.dll

I think my work computer still has 6.0.2 on it, so I can try that tomorrow for you if it would be useful.

scotthardwick avatar Oct 03 '18 04:10 scotthardwick

Hmmmm the binaries are there... And the startup script should be adding them before it can fail to resolve...

rjmholt avatar Oct 03 '18 04:10 rjmholt