Skip to content

Fix command history while debugging #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

SeeminglyScience
Copy link
Collaborator

This change fixes command history while debugging.

  • Fixed internal commands being added to command history.
  • Fixed ConsoleReadLine not retrieving history correctly.

This change fixes an issue where background commands would be added
to PowerShell's history.  This was due to a limitation in the
PowerShell debugger where the only way commands are excluded is if
the command is part of a hard coded set of commands. As a workaround,
a command from that set (prompt) is added as the first statement.

Resolves PowerShell/vscode-powershell#873
This change fixes an issue where the debugger was unable to obtain
command history.

Resolves PowerShell/vscode-powershell#550
@daviwil
Copy link
Contributor

daviwil commented Oct 27, 2017

Thanks so much for trying to fix this one! One thing I realized about using 'prompt' to suppress history, if the user has a custom prompt function that writes output directly to the console (Write-Host, etc), this approach might cause unwanted output to be written to the console. Can you try that and see if it's a problem?

@daviwil
Copy link
Contributor

daviwil commented Dec 6, 2017

Maybe if PSReadline support makes this unnecessary we can skip it, though it might be useful for cases where PSES is used without support for the terminal PSHost implementation.

@SeeminglyScience
Copy link
Collaborator Author

I'm torn about what to do with this. PSReadLine does solve this for the most part, but it still shows up in Get-History and it still increments the HistoryId. The latter is really annoying when using a customized prompt like PowerLine.

Write-Host won't bleed through on PSv3 or PSv5+. It doesn't on 3 because the fix doesn't apply, there is no Debugger.ProcessCommand. All debugger commands just go through nested pipelines which have a built in way to disable history. It doesn't on 5 because Write-Host writes to the information stream, which we redirect into output.

I haven't tested on 4, but I suspect that is where it would be an issue as it has ProcessCommand and does not have the information stream.

For those interested, this fix depends on undocumented logic in the debugger to disable history if the command is member of a specific set of commands. The commands are prompt, TabExpansion2, Set-PSDebuggerAction, Get-PSDebuggerStopArgs, and Set-PSDebugMode. prompt has the issues already discussed, and I discounted TabExpansion2 because is slow and potentially heavily customized. The last three I assume are used in workflow debugging, but I can't actually find any reference to them anywhere.

The way I see it there's a couple options:

  1. Create a empty function in the Commands module with the name of one of the last three commands

  2. Since any of these potential fixes depend on undocumented behavior, I could dig into reflection to see if there is anything we can do more directly for just PSv4

  3. Don't fix history for PSv4, only fix PSv3 and PSv5+

  4. Just use prompt as the fix across the board and acknowledge Write-Host as causing issues with debugging in PSv4

@TylerLeonhardt
Copy link
Member

@SeeminglyScience can we close this since it's addressed in your PSRL PR?

@SeeminglyScience
Copy link
Collaborator Author

@tylerl0706 Yeah I'll close it, but it's not 100% addressed. Functionally it is, but there's still some strange side effects like Get-History showing background commands and $MyInvocation.HistoryId still increments.

Either way this PR is way too old, new changes would have to be in a new PR anyway.

@SeeminglyScience SeeminglyScience deleted the fix-debugging-history branch September 6, 2018 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants