vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Reduce Integrated Console prompt output/noise while stepping through scripts

Open tysonflint opened this issue 8 years ago • 6 comments

System Details

Operation system name and version: Windows 8.1 (64-bit)

PS > code -v 1.13.0 376c52b955428d205459bea6619fc161fc8faacf

PS > code --list-extensions --show-versions [email protected]

PS > $PSVersionTable

Name Value


PSVersion 5.0.10586.117 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.10586.117 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Issue Description

I'm making the transition from using Quest/Dell's PowerGUI to Visual Studio Code with the vscode-powershell extension. While making this transition, I noticed a significant change in the way the console output behavior while running the debugger and steps through lines of code. When stepping through lines of code in the Visual Studio Code debugger (using F11) my PowerShell terminal returns a PowerShell prompt for every step taken, rather than just showing console output when something within the script's output is sent to the console. This behavior also occurs in PowerShell ISE, but does not occur within PowerGUI while stepping through lines of code. I often perform an "out-host" to display a status message which can be followed by several lines of code prior to the next "out-host" message to be written to the console. In PowerGUI the console window remains uncluttered while stepping through lines of code that don't write console output. I'm finding it difficult using the vscode etension to quickly review my status messages when they are spread apart by several lines of PowerShell prompts.

Could the vscode-powershell extension be modified, or have a configuration option added to it that will suppress the debug console output if only the prompt or a blank line is going to be displayed (but still allow for a blank when "" | out-host is used)? Would it also be possible to have an option to suppress the "Hit Line breakpoint on 'C:\temp\debug-step-test.ps1:1'" from the terminal output? I'd like to keep my terminal output the same whether I'm step debugging or running the script normally.

The desired behavior is that the terminal debug output would match the normal script execution output, while still allowing interaction with the script session (to change an object's property values for example) between the debug steps.

These are all the behaviors I'm used to with PowerGUI, but am trying to move away from it due to its end of life status. This is the download link for PowerGUI if you would like to see the desired behavior of the console window while stepping through the code: http://community-downloads.quest.com/powergui/Release/3.8/PowerGUI.3.8.0.129.msi

Thank you so much. I'm really looking forward to using Visual Studio Code with the vscode-powershell extension for writing my PowerShell scripts!

Tyson Flint

Example code to reproduce this issue:


$MyValue = 1
"status message 1" | out-host
for ($count = 1; $count -le 5; $count++)
{
	# Normally, you'd do a bunch of stuff in here
	# The console terminal should allow for changing the following value between debug steps.
	# Copy/Paste this next line in the terminal window while stepping through one iteration of this loop (remove the comment character):
	# $MyValue=10
	$MyValue++
}
"status message 2" | out-host
	
if ($MyValue -le 6)
{
	"You DID NOT modify the MyValue while stepping through the loop. 'MyValue' is: " + $MyValue | out-host
}
else
{
	"You MODIFIED the MyValue while stepping through the loop. 'MyValue' is: " + $MyValue | out-host
}
"" | out-host
"status message 3 - Blank line test. The line above should be blank whether debugging or not." | out-host

Normal script execution output:


status message 1
status message 2
You DID NOT modify the MyValue while stepping through the loop. 'MyValue' is: 6

status message 3 - Blank line test. The line above should be blank whether debugging or not.

Debug stepping through script output (notice it is difficult to find the status message):


Hit Line breakpoint on 'C:\Users\v-tysonf.REDMOND\Documents\Lenel-SQL-Inventory\debug-step-test.ps1:1'

[DBG]: PS C:\temp>
[DBG]: PS C:\temp>
status message 1
[DBG]: PS C:\temp>


[DBG]: PS C:\temp> [DBG]: PS C:\temp>




[DBG]: PS C:\temp> [DBG]: PS C:\temp>


[DBG]: PS C:\temp> [DBG]: PS C:\temp>




[DBG]: PS C:\temp> [DBG]: PS C:\temp>

status message 2


You DID NOT modify the MyValue while stepping through the loop. 'MyValue' is: 6


[DBG]: PS C:\temp> [DBG]: PS C:\temp>
status message 3 - Blank line test. The line above should be blank whether debugging or not.
[DBG]: PS C:\temp>

tysonflint avatar Jun 15 '17 18:06 tysonflint

Hey Tyson, thanks for giving the PowerShell extension a shot! The primary reason that we write the prompt out when the debugger stops is because the console is where you'd enter commands if you want to interact with the session while stopped. Does PowerGUI have a separate UI element for entering commands while debugging? If not, how do you know where to type? Maybe that's not part of your workflow at all?

I'm definitely willing to consider adding a setting for this if we can find a good user experience for it as you're not the first person who's mentioned the prompt noise while stepping.

daviwil avatar Jun 16 '17 01:06 daviwil

Regardless of the prompt noise, it seems there are some unnecessary newlines in the output so I'll see if I can figure out what's going on there.

daviwil avatar Jun 16 '17 01:06 daviwil

David, PowerGUI has a prompt at the bottom of the screen that never appears to be scroll up into the script's output. So I would say "yes" that it does have a separate UI element for entering commands while debugging even though there is no visible division for it within the console's window. You can continue issuing commands between steps on this prompt, and then a copy the prompt will finally appear along with the command that you issued within the console's output. However the interactive prompt never appears inline with the script output unless you actually use the prompt. This makes up a very clean console output. :1st_place_medal:

You can see this behavior in this video at 1:20 minute into this video (linked at 1:15). Although the script is executed at once without stepping, the behavior is the same as if you were stepping through multiple lines. The output appears within the console, but the prompt always remains at the bottom of the screen. Typing into the prompt at the bottom of the screen will result in a copy of the prompt and the command appearing within the console output. This is the only time you'll see the prompt in the console window.

Seeing the desired user experience in action might be better than the description or video I just gave. Here's a link to the PowerGUI installer MSI if you'd like to see it in action. It's a simple and small install (about 30MB installed with the default feature selection). Once installed, the editor is located at: C:\Program Files (x86)\PowerGUI\ScriptEditor.exe. Hit F11 to start debug stepping, no breakpoint required.

tysonflint avatar Jun 16 '17 07:06 tysonflint

Hi Dave. To reply to your comment above. When I'm debugging every time I hit a breakpoint, or step through, the cursor always jumps into the code and not the console (which you say it should), Means I always end up overwriting my code when I'm trying to type in the console! Is this known or expected?

davebrannan avatar Jun 26 '17 19:06 davebrannan

@davebrannan this is unavoidable at the moment. VS Code doesn't let me change the focus behavior when stepping, they always pop focus back to the editor. I could do a workaround that forces the cursor to go back to the console but there'd be a split second where the cursor would be jumping back to the editor anyway.

I filed an issue against VS Code to provide me a way to control the focus behavior: https://github.com/Microsoft/vscode/issues/23117. I'd recommend commenting there to let them know that users are having a poor debugging experience due to this.

daviwil avatar Jun 26 '17 20:06 daviwil

Hi, I'm just following up on this to see if any progress has been made. I checked the issue @davebrannan linked (https://github.com/microsoft/vscode/issues/23117) and it appears that the toggle has been implemented: image

And the PowerShell extension now has a powershell.integratedConsole.focusConsoleOnExecute setting.

But I don't see an option to prevent the [DBG]: PS C:\... prompt from printing in the console on every breakpoint. I've been working on an interactive menu and the extra lines can invalidate debug runs: image

Thanks

jerred121 avatar Dec 14 '23 00:12 jerred121