PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code

Home Page:https://marketplace.visualstudio.com/items/ms-vscode.PowerShell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Skip all Write-Host when debugging

ALIENQuake opened this issue · comments

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.

Summary

Hi,

recently I've been facing many 'Write-Host' instances and it slows down executing the next lines.

Any way to skip such lines? Does the debugger can skip some lines at all?

Proposed Design

No response

Thanks for the issue, @ALIENQuake

We actually believe that the slowness is due to PowerShell being in a debugging state which takes away some of the optimizations

That might be true but even so, this feature request is not about slowdowns during step-by-step debugging. It's about not having to press F10/F11 several times without losing any valuable information when debugging. Let's consider the following example:

New-MyCommand -Value '1'
Write-Host "Title:"
Write-Host "Output A: $A"
Write-Host "Output B: $B"
Write-Host "Output C: $C"
Write-Host "Preparing next steps"
New-MyOtherCommand -Value '1'

When I'm debugging this code several times, I don't really care about what Write-Host lines will show. I only care about the effect of two commands that actually do stuff.

Please reconsider this.

It's not an uncommon practice for folks to actively step Write-Hosts that contain state to see the values as execution happens. While log points or utilizing hover/variable pane may be a more (subjectively) efficient pattern, skipping Write-Host would be confusing for a lot of users.

If you have a large portion of code you'd like to quickly step over, the easiest workaround is enclosing them in their own scriptblock:

New-MyCommand -Value '1'
& { 
    Write-Host "Title:" # Once you step here, use "Step Out" to get to `New-MyOtherCommand`
    Write-Host "Output A: $A"
    Write-Host "Output B: $B"
    Write-Host "Output C: $C"
    Write-Host "Preparing next steps"
}

New-MyOtherCommand -Value '1'

This issue has been marked as resolved and has not had any activity for 1 day. It has been closed for housekeeping purposes.