Fix STDOUT leaking into LSP messages
This PR addresses the problem of the print and inspect commands leaking their output to the LSP, causing their outputs to be misconstrued as LSP messages.
It does so by prepending shadowed definitions for these commands to a copy of the user's env.nu file, then saving that prepended env.nu as a temp file, and using that temp file's path and passing it along as --env-config to the nu binary.
This makes it so that the print and inspect commands will check if there is an environment variable named NUSHELL_LSP, and if it's value is one of [ 1, '1', true, 'true' ]. If so, those commands will not print, thereby solving the problem of those commands leaking their output to STDOUT / the LSP.
Some notes:
- The path to the user's
env.nufile is determined by launching thenubinary with--commands '$nu | select -o env-path | to json, then parsing the output. This might be unnecessary complexity. It also may fail, if the user does not have aenv.nufile. We may want to address that. - The text of the user's
env.nufile is read into memory, since we need to copy it and prepend to it, in order to shadow theprintandinspectcommands, while still respecting any changes the user has made to theirenv.nufile. Some might object ot the text being read into memory, although we do not do anything with it other than copy it to a temp file-- it's not uncommon for dev secrets to be exposed in plain text inenvfiles.
I originally wanted to try to just pass the shadowed commands via --commands or --execute, but I couldn't get that to work. So I used the --env-config trick instead.
This entire PR is made obsolete if nushell's LSP mode is changed upstream, so that the print and inspect commands do not interfere with the LSP's output.