mxsdev / nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug
276 stars 30 forks source link

How to debug in an externalTerminal? #56

Closed carljo-reyes closed 1 year ago

carljo-reyes commented 1 year ago

Hello

The issue I'm having is that the debugger does not attach when I set console to externalTerminal in the launch config.

my goal is to be able to see the logs of a debugged node.js app on a tmux pane. I use nodemon to start the server.

The initial approach I went for was to attach a debugger to a running nodemon process (i tried to attach to other node processes too), however, the debugger is not able to reattach to the app despite having the restart set to true on the launch config.

The next approach I tried was to launch the app directly from DAP. To my luck, the debugger attaches to all relevant node process to debug the app, as well as re-attach itself every time the server restarts.

Finally, I tried to look for ways to have the console output displayed at an external terminal. I was able to launch the app but the debugger isn't able to automatically attach to it

Please feel free to correct any terminologies I used incorrectly. I'm quite new in setting up nvim and dap configs

Below is an except of my config

require("dap").defaults.fallback.external_terminal = {
    command = "tmux",
    args = { "split-pane", "-h" }
}

local DEBUGGER_PATH = '/home/xxx/.local/share/nvim/lazy/vscode-js-debug'
...
        for _, language in ipairs { "typescript", "javascript" } do
            require("dap").configurations[language] = {
                {
                    type = "pwa-node",
                    request = "attach",
                    name = "Attach to process", -- works but disconnects every server restart. needs manual reconnection
                    processId = require("dap.utils").pick_process,
                    rootPath = "${workspaceFolder}",
                    cwd = "${workspaceFolder}",
                    restart = true,
                },
                {
                    type = "pwa-node",
                    request = "launch",
                    name = "npm run dev-debug (external)", -- doesn't attach to app
                    -- trace = true, -- include debugger info
                    runtimeExecutable = "npm",
                    runtimeArgs = {
                        "run",
                        "dev-debug",
                    },
                    rootPath = "${workspaceFolder}",
                    cwd = "${workspaceFolder}",
                    console = "externalTerminal",
                    internalConsoleOptions = "neverOpen",
                },
                {
                    type = "pwa-node",
                    request = "launch",
                    name = "npm run dev-debug (console)", -- works flawlessly
                    -- trace = true, -- include debugger info
                    runtimeExecutable = "npm",
                    runtimeArgs = {
                        "run",
                        "dev-debug",
                    },
                    rootPath = "${workspaceFolder}",
                    cwd = "${workspaceFolder}",
                    console = "integratedTerminal",
                    internalConsoleOptions = "neverOpen",
                },
            }
        end
carljo-reyes commented 1 year ago

I just rearranged my dap-ui elements and zoom my tmux vim pane as needed. Closing this as I'm not really sure if it's a problem with nvim-dap, js language server, or this plugin. Will try to look into this further and reopen as needed.

Many thanks for this awesome plugin!