mxsdev / nvim-dap-vscode-js

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

Node process doesn't get killed when terminating a debug session #45

Open anatskiy opened 1 year ago

anatskiy commented 1 year ago

When I try to run a debug session of a basic node server, I can debug it just fine. But when I terminate the session (require('dap').terminate()) or disconnect from it (require('dap').disconnect({ terminateDebuggee = true })) and then rerun a new session, I get an error about the node server port being already in use, meaning, that the previous node process wasn't properly closed. I'm clueless about what to do ☹️

I've got the following config:

local DEBUGGER_PATH = vim.fn.stdpath('data') .. '/lazy/vscode-js-debug'

require('dap-vscode-js').setup({
  debugger_path = DEBUGGER_PATH,
  adapters = {
    'pwa-node',
    'pwa-chrome',
    'node-terminal',
  },
})

local dap = require('dap')

for _, language in ipairs({ 'typescript', 'javascript' }) do
  dap.configurations[language] = {
    {
      type = 'pwa-node',
      request = 'launch',
      name = 'Launch',
      program = '${file}',
      cwd = '${workspaceFolder}',
    },
    ...
  }
end

The installed version of vscode-js-debug is 1.78.0

zyriab commented 1 year ago

I'm working on it at the moment as I am implementing an extension to run the user's npm scripts directly from the DAP's options selector. For the moment, the only way to do it from within Neovim that I found is to go into DAP-UI's integrated terminal (console), enter insert mode and press <C-c>.

I'm looking into a way to catch the terminal ID and kill it but in the meantime, that's the only solution I've found that's not too cumbersome. Here's my config, for reference. It's the same as the readme, the interesting part is:

 {
    name = "Run npm script",
    type = "pwa-node",
    request = "launch",
    cwd = "${workspaceFolder}",
    rootPath = "${workspaceFolder}",
    sourceMaps = true,
    skilpFiles = { "<node_internals>/**" },
    protocol = "inspector",
    console = "integratedTerminal",
    runtimeExecutable = "npm",
    runtimeArgs = {
        "run-script",
        "YOUR_NPM_SCRIPT" -- e.g.: "start"
    }
}

The interesting line is console = "integratedTerminal" It works for "launch" and probably "attach" as well

I'll repost when (if?) I find a way to do that automatically.

Cheers