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

Debug Session Clutters Terminal Command History

Open mike-the-automator opened this issue 8 years ago • 14 comments

System Details

  • Operating system name and version:
  • VS Code version:
  • PowerShell extension version:
  • Output from $PSVersionTable:


PS C:\Temp> code -v
1.13.0
376c52b955428d205459bea6619fc161fc8faacf
PS C:\Temp> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      3      2      0


PS C:\Temp> code --list-extensions --show-versions
[email protected]
[email protected]
PS C:\Temp> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.1198
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1198
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with commands being inserted into the command history by a debugging session. The additional commands seem to be related to the debugging session. I have reproduced this issue with a simple .ps1 file containing a single variable assignment, with a breakpoint set on the line.

Repro.ps1: $x=1

The entires I'm referring to are Ids 5-9 in the below transcript. The "Get-Variable" entries in the command history appear to be triggered by hovering the mouse over a variable in the editor window to view its value. I'm not sure what triggers the ones.

PS C:\Projects\SQLServerDBA\PowerShellModulesV2> c:\Temp\repro.ps1


PS C:\Temp> get-history

  Id CommandLine
  -- -----------
   1 get-module
   2 gci c:\temp\
   3 c:\Temp\repro.ps1


PS C:\Temp> c:\Temp\repro.ps1



Hit Line breakpoint on 'C:\Temp\repro.ps1:1'

[DBG]: [DBG]: PS C:\Temp>
PS C:\Temp> Get-history

  Id CommandLine
  -- -----------
   1 get-module
   2 gci c:\temp\
   3 c:\Temp\repro.ps1
   4 get-history
   5 @{ 'computerName' = $env:ComputerName; 'processId' = $PID; 'instanceId'...
   6 Get-Variable
   7 Get-Variable
   8 $global:__psEditorServices_CallStack = Get-PSCallStack; $global:__psEdi...
   9 Get-Variable
  10 c:\Temp\repro.ps1

mike-the-automator avatar Jun 13 '17 19:06 mike-the-automator

Thanks Mike! This is coming from PowerShell, I had filed a bug on it some time ago:

https://github.com/PowerShell/PowerShell/issues/3109

I'll see if I can find a workaround that doesn't cause these commands to be added to your history.

daviwil avatar Jun 13 '17 20:06 daviwil

@SydneyhSmith @TylerLeonhardt EDIT: Can Reproduce now: image

JustinGrote avatar Apr 22 '20 16:04 JustinGrote

Get-History is still dirty FWIW. Until an option is added to the debugger API to skip adding to history, there won't really be a good way to fix that though :/

SeeminglyScience avatar Apr 22 '20 18:04 SeeminglyScience

Any updates on this? Just wasted a few hours debugging a Start-Transcript call in my code only to realize that the strange logs was caused by the debugger itself from the VS Code PowerShell extension.

TheOnlyWei avatar Mar 30 '22 21:03 TheOnlyWei

Um, well, it is fixed in the preview as of right now, but our fix might not be viable long-term. Give the preview a try!

andyleejordan avatar Mar 31 '22 00:03 andyleejordan

@TheOnlyWei Did you get a chance to try the Preview?

andyleejordan avatar Apr 04 '22 23:04 andyleejordan

@andschwa The 7.3-preview does not seem to list this fix in the change description. I switched VS code integrated console to PowerShell Core 7.3-preview anyway and it didn't fix anything. Did it work for you on your machine?

TheOnlyWei avatar Apr 05 '22 18:04 TheOnlyWei

The latest code is available in the PowerShell Preview for VS Code, and includes a myriad of fixes. Could you verify if this issue still reproduces using the preview extension? Please note that this preview is likely to include other bugs, and you should feel free to file new issues for those so we can work through them. Thanks again!

andyleejordan avatar Apr 06 '22 17:04 andyleejordan

@TheOnlyWei See my reply above, I meant the preview of the extension, not PowerShell's preview version itself (sorry for the confusion). Thanks!

andyleejordan avatar Apr 06 '22 17:04 andyleejordan

@andschwa The output clutter is greatly reduced, but still getting some stuff like the following that is not output in the console:

PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Global"
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Script"
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Local"
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Local"

TheOnlyWei avatar Apr 06 '22 18:04 TheOnlyWei

Ah! Thanks @TheOnlyWei, can definitely fix the rest of this!

andyleejordan avatar Apr 12 '22 22:04 andyleejordan

Well, that's interesting. I'm actually not sure why those last bits are showing up, as the default for AddToHistory is false, so they shouldn't be.

andyleejordan avatar Apr 12 '22 23:04 andyleejordan

Going to leave this one open to track the remaining work.

andyleejordan avatar Apr 13 '22 01:04 andyleejordan

Hey @TheOnlyWei can you test the latest release and let me know both what you see and how you test it? I'd like to get this finished if I can.

andyleejordan avatar Sep 02 '22 17:09 andyleejordan

Closing this as resolved

SydneyhSmith avatar Mar 07 '23 20:03 SydneyhSmith