Skip to content

Instantly share code, notes, and snippets.

@SeeminglyScience
Created May 5, 2022 14:54
Show Gist options
  • Save SeeminglyScience/c2c4e61d06c99dc101f506f4506c89cd to your computer and use it in GitHub Desktop.
Save SeeminglyScience/c2c4e61d06c99dc101f506f4506c89cd to your computer and use it in GitHub Desktop.
Explanation of benefits of the integrated console in VSCode

(Context)

So first it's important to note that both actually use pwsh. While we do of course need a custom PSHost in order to provide an integrated experience, most of the calls just go right back to the same implementation of whatever version of PowerShell you're running.

That said, here's a few benefits of using the PowerShell Integrated Console vs a non-integrated terminal:

Debugger

When you hit a breakpoint in the debugger the PSIC is running in that context. So you can interactively inspect (and mutate) the state of the script you're running. You can also execute debugger commands from there:

 s, stepInto         Single step (step into functions, scripts, etc.)
 v, stepOver         Step to next statement (step over functions, scripts, etc.)
 o, stepOut          Step out of the current function, script, etc.

 c, continue         Continue operation
 q, quit             Stop operation and exit the debugger
 d, detach           Continue operation and detach the debugger.

 k, Get-PSCallStack Display call stack

 l, list             List source code for the current script.
                     Use "list" to start from the current line, "list <m>"
                     to start from line <m>, and "list <m> <n>" to list <n>
                     lines starting from line <m>

 <enter>             Repeat last command if it was stepInto, stepOver or list

 ?, h                displays this help message.

Set up intellisense

Because the PSIC and the editor pane share the same context, you can import modules, create variables/functions, etc and they will be reflected in intellisense

F8 run selection

There are other extensions that can do something similar, but they all send selected text as direct input to the console. This can sometimes cause issues if your selected text must run as a unit of code (like if you have else's that aren't cuddled) or if you have custom PSReadLine key handlers.

In the integrated console your selection is sent and processed by the language server so you can be sure that your selection is interpreted how you expect.

$psEditor

This is an automatic variable in the integrated console that lets you interact with the editor with code. This lets you do things like Get-ChildItem | Out-CurrentFile to add text to the current editor from the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment