PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
612 stars 207 forks source link

Add `UseNullPSHostUI` config so apps hosting PSES can disable it #2122

Closed dkattan closed 4 months ago

dkattan commented 6 months ago

PR Summary

Meaningful output from PSES's internal PowerShell is suppressed if you don't specify -EnableConsoleRepl.

PR Context

I'd like to be able to see the output from PSScriptAnalyzer but my application has a read-only terminal. This SwitchParameter prevents the UI from being set to NullPSHostUI without enabling Repl functionality.

Perhaps a better way to implement this would be to condition off the use of named pipes as I believe the intention of the following code is to prevent clobbering stdio since ConsoleRepl can only be used when connecting via named pipes.

     UI = hostInfo.ConsoleReplEnabled || hostInfo.UseCurrentPSHostUI
                ? new EditorServicesConsolePSHostUserInterface(loggerFactory, hostInfo.PSHost.UI)
                : new NullPSHostUI();
dkattan commented 6 months ago

I like quite a bit of this but would want to clean it up a bit, put it through some thorough testing, and I think you are quite right that we should condition this based on named pipes instead of adding (yet another) parameter to the startup script. Let me know if you want to do some of that, and please tell me about the best way to go about testing this!

Sweet, I'll go ahead and make that change

dkattan commented 6 months ago

please tell me about the best way to go about testing this!

This is going to be hard to test since it appears that all the tests use Stdio, unless I’m mistaken.

andyleejordan commented 4 months ago

That CI failure was a red herring, it was actually caused by GitHub Actions giving us a mix of PowerShell versions leading to a missed bug in a unit test, fixed by https://github.com/PowerShell/PowerShellEditorServices/pull/2135