PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

Missing output stream when debugging from neovim

Open Willem-J-an opened this issue 1 year ago • 2 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [X] I have searched all issues to ensure it has not already been requested.

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

Willem-J-an avatar Dec 21 '23 21:12 Willem-J-an

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

andyleejordan avatar Jan 03 '24 22:01 andyleejordan

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 avatar Jan 03 '24 22:01 Willem-J-an

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] [31;1mNew-AzResourceGroupDeployment: [0mdeploy_workbooks.ps1:49[0m
[31;1m[0m[36;1mLine |[0m
[31;1m[0m[36;1m[36;1m  49 | [0m     [36;1mNew-AzResourceGroupDeployment `[0m
[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m     | [31;1m     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m

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 avatar Mar 19 '24 12:03 Willem-J-an

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

Willem-J-an avatar Mar 19 '24 13:03 Willem-J-an

Awesome news, thanks for sharing!!!

andyleejordan avatar Mar 19 '24 19:03 andyleejordan

I think you could try:

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

to disable the color codes.

andyleejordan avatar Mar 19 '24 19:03 andyleejordan