PowerShell / PowerShellEditorServices

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

Missing output stream when debugging from neovim #2119

Closed Willem-J-an closed 3 months ago

Willem-J-an commented 6 months ago

Prerequisites

Summary

I'm trying to integrate neovim DAP client with powershell. Recently support was added for named pipes in the client, so I got to work and got the integration working. I can launch the debugger, use breakpoints, step through, evaluate expressions, all good.

The only problem is: I don't seem to get the output stream of the actual script. No output when I simply run the script, and neither on the repl. The only way to get output is using the evaluating expressions or watching expressions. The integration is working to some extent; for example I can do $x = 'a' in the repl, and if I watch $x it will show 'a'. Is there any obvious reason from the perspective of my configuration that could explain this behaviour?

            local PSES_BUNDLE_PATH = vim.fn.expand("~/.local/share/nvim/mason/packages/powershell-editor-services")
            local tmpdir = os.tmpname() .. "d"
            os.execute("mkdir " .. tmpdir)
            dap.adapters.ps1 = {
                type = "pipe",
                pipe = "${pipe}",
                executable = {
                    command = "pwsh",
                    args = {
                        "-NoLogo",
                        "-NoProfile",
                        "-NonInteractive",
                        "-OutputFormat",
                        "Text",
                        "-File",
                        PSES_BUNDLE_PATH .. "/PowerShellEditorServices/Start-EditorServices.ps1",
                        "-BundledModulesPath",
                        PSES_BUNDLE_PATH,
                        "-LogPath",
                        tmpdir .. "/logs.log",
                        "-SessionDetailsPath",
                        tmpdir .. "/session.json",
                        "-HostName",
                        "Neovim",
                        "-HostProfileId",
                        "Neovim.DAP",
                        "-HostVersion",
                        "1.0.0",
                        "-LogLevel",
                        "Normal",
                        "-DebugServiceOnly",
                        "-DebugServicePipeName",
                        "${pipe}"
                    },
                },
            }
            require("dap.ext.vscode").load_launchjs()
// launch.json object
{
            "name": "PowerShell: Current",
            "type": "ps1",
            "request": "launch",
            "script": "${file}",
            "cwd": "${file}",
            //"createTemporaryIntegratedConsole": true // Does not really change the behaviour
        }

Proposed Design

No response

andyleejordan commented 6 months ago

I wonder if this is related to what @dkattan was seeing (and fixing) in #2122.

Willem-J-an commented 6 months ago

Could be related indeed. If I pass the -EnableConsoleRepl switch everything crashes and burns so I'm not passing that flag. Would that cause suppression of output though pses dap?

Willem-J-an commented 3 months ago

Hi @andyleejordan,

Getting back to doing some powershell debugging; seems like some improvements were made on the above topics! I can see stdout and stderr output now:

[debug-adapter stdout] Using context;

[debug-adapter stderr] New-AzResourceGroupDeployment: deploy_workbooks.ps1:49
Line |
  49 |      New-AzResourceGroupDeployment `
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Unfortunately, the colors codes are not interpreted on neovim dap client. Is there a way to disable the color codes, or would you have any other suggestions how to deal with this ?

Thanks!

Willem-J-an commented 3 months ago

For posterity: I found a way to make it work using Baleia:

{
        "m00qek/baleia.nvim",
        tag = "v1.4.0",
        config = function()
            local baleia = require("baleia").setup()
            vim.api.nvim_create_user_command("Baleia", function()
                baleia.automatically(vim.fn.bufnr("%"))
            end, {})
        end,
    }

image

andyleejordan commented 3 months ago

Awesome news, thanks for sharing!!!

andyleejordan commented 3 months ago

I think you could try:

$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;

to disable the color codes.