r/PowerShell • PowerShell ISE Code Engineer • Mar 15 '17

Just released v0.10.0 of the PowerShell extension for Visual Studio Code with an integrated console experience like the ISE!

https://twitter.com/daviwil/status/841800580108447744
166 Upvotes

42 comments sorted by

21

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

New interactive console experience

We are excited to provide you with the first release of our new interactive console experience! When you open up a PowerShell script file, you will be greeted with a new VS Code integrated terminal window called "PowerShell Integrated Console"

integrated console screenshot

In this console you will have an experience that falls somewhere between the PowerShell ISE and the PowerShell console host:

  • Tab completion of commands and their parameters

  • Basic command history, accessed using the up/down arrow keys

  • The psedit command opens existing files in an editor pane

  • Pressing <kbd>F8</kbd> in an editor pane runs the current line or selection in the console

  • Native applications like git are fully supported

  • Script debugging shares the same console session with the editor for a true ISE-like debugging experience

It even works with your fancy prompt function if configured in your VS Code profile ($HOME\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1):

custom prompt screenshot

The integrated console is supported on PowerShell v3 through v6 and works on Linux and macOS with PowerShell Core. By default you don't have to configure which PowerShell to run, we will pick an appropriate default based on your platform. If you'd like to choose a different install of PowerShell you can always change the powershell.developer.powerShellExePath setting.

Keep in mind that this is the first release for this feature and there are bound to be issues and missing functionality. Please feel free to file GitHub issues for any bugs or feature requests!

Known Issues and Limitations
  • #535 PSReadline is currently not supported in the integrated console. We will enable this in a future release.

  • #534 Integrated console prompt is not restarted when you stop the debugging of a local runspace in another process. This will be addressed soon in a patch update.

  • #533 Backspace key does not work in the integrated console on Linux and macOS. The workaround for now is to use <kbd>Ctrl+H</kbd> instead of the Backspace key. This will be addressed soon in a patch update.

  • #536 Integrated console sometimes does not have a scrollbar at startup. The workaround is to resize the width of the VS Code window slightly and the scrollbar will appear. This will be addressed soon in a patch update.

Get-Credential and PSCredential support

Now that we have the integrated console, we have added support for the Get-Credential cmdlet, Read-Host -AsSecureString, and any input prompt of type SecureString or PSCredential. When you run any of these cmdlets you will be prompted inside the integrated console:

credential screenshot

Code formatting improvements

We now support VS Code's editor.formatOnType setting so that your code gets formatted as you type! Formatting will be triggered when you press Enter or the closing curly brace character }.

Based on your feedback, we've also added new code formatting options, all of which are turned on by default:

  • powershell.codeFormatting.newLineAfterCloseBrace - Causes a newline to be inserted after a closing brace in multi-line expressions like if/else

  • powershell.codeFormatting.whitespaceBeforeOpenBrace - Causes whitespace to be inserted before an open brace like Foreach-Object {

  • powershell.codeFormatting.whitespaceBeforeOpenParen - Causes whitespace to be inserted before an open parentheses like if (

  • powershell.codeFormatting.whitespaceAroundOperator - Causes whitespace to be inserted around operators like = or +

  • powershell.codeFormatting.whitespaceAfterSeparator - Causes whitespace to be inserted around separator characters like ; and ,

  • powershell.codeFormatting.ignoreOneLineBlock - Single-line expressions, like small if/else statements, will not be expanded to multiple lines.

We've also made many improvements to the performance and stability of the formatter.

Debugging improvements

We've added a new configuration for debugging your Pester tests. By default it merely runs Invoke-Pester at the workspace path, but you can also edit the configuation to add additional arguments to be passed through.

We've also added support for column breakpoints. Now you can set a breakpoint directly within a pipeline by placing your cursor at any column on a line and running the Debug: Column Breakpoint command:

column breakpoint screenshot

For the latest PowerShell Core release (6.0.0-alpha.17), we have also added the ability to step into ScriptBlocks that are executed on another machine using Invoke-Command -Computer.

Set a breakpoint on an Invoke-Command line and then once it's hit:

Invoke-Command screenshot

Press F11 and you will step into the ScriptBlock. You can now continue to use "step in" and trace the ScriptBlock's execution on the remote machine:

remote script listing screenshot

Note that you cannot currently set breakpoints in the script listing file as this code is being executed without an actual script file on the remote machine.

Other fixes and improvements

  • Fixed #427 - The keybinding for "Expand Alias" command has been changed to <kbd>Shift+Alt+E</kbd>

  • Fixed #519 - Debugger hangs after continuing when watch expressions are set

  • Fixed #448 - Code formatter should keep indentation for multi-line pipelines

  • Fixed #518 - Code formatter fails when dollar-paren $() expressions are used

  • Fixed #447 - Code formatter crashes when run on untitled documents

6

u/[deleted] Mar 15 '17

Sweet baby Jesus you just made my week. I love to work in VS Code. I hate that I've had to switch to ISE to do inline testing.

Now I can test in Powershell, paste into Code, test as part of script, and go on about my day.

Godsend.

2

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Let me know if there are any remaining rough spots after you've used it for a bit. I want to make the interactive workflow as smooth as possible.

2

u/[deleted] Mar 15 '17

The one hang-up I've discovered so far is some weird behavior of the prompt after running some code.

I've got a script I'm working on, I hit f5, it does its thing, and when the console should return to normal it's cutting off several characters in the path and the >

During this time I can type a command, for example a simple dir, and hit enter, the command will execute, and after the prompt returns to normal.

Strange, and only slightly annoying. I can put in an Issue on Github to better track this if you'd like.

1

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Hmmm, strange. I'd definitely appreciate it if you could file a bug for that including some screenshots so I can see what it's doing.

0

u/[deleted] Mar 15 '17

[deleted]

3

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

I've got a fix for this, will be shipping an update today.

0

u/[deleted] Mar 15 '17

[deleted]

3

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Just a bug in my code, I was throwing away any key inputs using Ctrl or Alt.

5

u/ka-splam Mar 15 '17

Cool. Installed.

From the terminal, Ctrl-Tab brings me back to the editor, but Ctrl-Tab doesn't go down to the console. Nor do the ISE shortcuts ctrl-d/ctrl-i do anything. Nor does the classic Windows F6 shortcut switch windows. Is there a default 'switch focus to Terminal' shortcut?

Ctrl-' will do it but only via turning the Terminal off and on again...

3

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Yeah, there are some rough spots when it comes to toggling terminal focus. The VS Code team is talking about changing this behavior:

https://github.com/Microsoft/vscode/issues/19400

Regarding Ctrl+D/Ctrl+I, I'm planning to add those keybindings through a new extension which replicates the ISE keybindings:

https://github.com/PowerShell/vscode-powershellise-keybindings/issues/1

What is your preferred behavior for this?

3

u/icklicksick Mar 15 '17

You are a god amongst men. Thank you for doing what you do.

2

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Thanks a lot!

2

u/cantrecall Mar 15 '17

Thank you! Been waiting anxiously for the Get-Credential support!

0

u/[deleted] Mar 15 '17

[deleted]

4

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

I definitely would like for the PowerShell extension to be so good that nobody will want to use the ISE anymore, but there's no plan to make the ISE go away or be replaced entirely by VS Code.

1

u/[deleted] Mar 15 '17

I sure hope so. The ISE has its place, but VS Code has potential to be so much greater.

2

u/dastylinrastan Mar 15 '17

Awesome work David, thanks for putting in some blood and sweat on this and closing a lot of those last-mile ISE gaps.

1

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Thanks a lot!

2

u/AdmiralCA Mar 15 '17 edited Mar 15 '17

David - brilliant work as always!

Not sure if this bug goes to you or to the Code team but....

(testing on Win10) When hitting the trashcan on on the Integrated PowerShell Console, it would pop an error saying that it closed incorrectly, and ask if I wanted to restart the session.

Thoughts?

Edit: In regards to a question now deleted - I realized that the session wasn't viewing the file as PowerShell, and therefore wouldn't give me the Integrated Console as an option for a terminal.

2

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

That restart prompt is mine, the idea there is that if the language server crashes it should prompt the user to restart for the sake of convenience. Are there cases when you want to close the integrated console entirely?

2

u/AdmiralCA Mar 15 '17

I guess my use case is for "wiping the slate clean". I understand the idea of crash/notify, but I wouldn't expect it from a button press.

2

u/zenmaster24 Mar 15 '17

cool - does this mean vscode supports multiple terminals now? i dont have to edit my preferences to set the default to powershell anymore?

edit - i use vscode with python and bash shells in the terminal as well (win 10 wsl for bash)

1

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

You don't need to set your default terminal for PowerShell if all you want is to use the Integrated Console, I'm in control of which PowerShell gets launched in that case. If you've never configured your default terminal setting and you open a .ps1, the PowerShell Integrated Console will open with the correct PowerShell path based on your platform.

Does that make sense?

1

u/Emiroda Mar 15 '17

You still need to set a default terminal in settings.json.

1

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Not for the Integrated Console, it runs powershell.exe automatically without configuration.

1

u/Emiroda Mar 15 '17

That's true, but if he wants bash or python shell, he needs to specify it, correct?

3

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Yep, absolutely. You can use /u/Tyriar's vscode-shell-launcher to make this easier:

https://github.com/Tyriar/vscode-shell-launcher

2

u/zenmaster24 Mar 16 '17

wow this is exactly what i wanted vscode to do natively! thankyou so much for showing me this exists!

2

u/Emiroda Mar 15 '17

It's fucking amazing, let me tell you that.

I have one single feature request: Color coding in the terminal via PSReadline :)

3

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Yep, PSReadline support is coming but it will require a bit of work. Might take a couple more months, but hopefully less.

4

u/joerod Mar 15 '17

Very happy with this. I like VS code but there were a few things missing that kept me using ISE for PowerShell development. Seems like your closing the gap with this release.

1

u/Swarfega Mar 15 '17

Great job on this.

Is there a way to cycle through matching cmdlets via autocomplete (tab) rather than being like Unix style as it is now and just autocompletes the first matching cmdlet?

1

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

If you keep pressing tab, it cycles through the completions for the current word. Maybe you're suggesting something different?

2

u/Swarfega Mar 15 '17

Yeah so if i type Get-C then keep pressing tab in the ISE it cycles through all available cmdlets that begin with Get-C. VSCore just autocompletes the first cmdlet it matches.

2

u/daviwil PowerShell ISE Code Engineer Mar 15 '17

Oh, you mean in the editor, not the console, right? I'll look into that, there must be a way to do it now.

2

u/Swarfega Mar 15 '17

Sorry yes the editor. You can change how this behaves in PSReadLine.

Set-PSReadlineOption -EditMode Emacs

When you press tab twice is like Unix where it displays all cmdlets that match.

Set-PSReadlineOption -EditMode Windows

Is what we're used to in PowerShell where it cycles though matching cmdlets.

2

u/Teh_Fonz Mar 15 '17

Thank you! Recently started using Powershell in VSC and love the editing capabilities but still go back to ISE for the integrated console. Hopefully this means I can to stick with one scripting tool!

1

u/Scrltvx Mar 15 '17

Cheers, will try this out and provide feedback.

1

u/TheShadowhawk Mar 15 '17

excellent work! I can see my need to use the ISE dropping less and less!

1

u/[deleted] Mar 15 '17

This is easily the best news I have heard today. God bless you and all your nephews.

1

u/soopaman20 Mar 15 '17

I haven't opened ISE today since this release. I love it and look forward to further changes for the niggle things. Got so much to play with.

Top work u/daviwil

1

u/nkasco Mar 16 '17

This is so awesome, can I finally say goodbye to the ISE though?

1

u/[deleted] May 29 '17

My heroes!