mxsdev / nvim-dap-vscode-js

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

Getting error: adapter.port is required for server adapter #42

Closed ChilloManiac closed 1 year ago

ChilloManiac commented 1 year ago

I've tried to get debugging in jest working but im getting the following error.

Error executing luv callback:                                                                                                                                                                                                                                                                                                                                                               
.../.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1223: adapter.port is required for server adapter                                                                                                                                                                                                                                                                               
stack traceback:                                                                                                                                                                                                                                                                                                                                                                            
        [C]: in function 'assert'                                                                                                                                                                                                                                                                                                                                                           
        .../.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1223: in function <...hNoe/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1215>  

Im using lazy as a package manager with the following config:

local M = {
  "mfussenegger/nvim-dap",
  dependencies = {
    { "rcarriga/nvim-dap-ui" },
    {
      "mxsdev/nvim-dap-vscode-js",
      tag = "v1.1.0",
    },
    {
      "microsoft/vscode-js-debug",
      tag = "v1.74.1",
      build =
      "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
    },
  },
  keys = { 
  -- Snippet out for brevity
  }
}

M.config = function()
  require('dap-vscode-js').setup({
    debugger_path = vim.fn.stdpath('data') .. '/lazy/packages/vscode-js-debug',
    debugger_cmd = { 'js-debug-adapter' },
    adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
  })

  local dap = require('dap')

  -- language config
  for _, language in ipairs({ 'typescript', 'javascript' }) do
    dap.configurations[language] = {
      {
        type = "pwa-node",
        request = "launch",
        name = "Debug Jest Tests",
        -- trace = true, -- include debugger info
        runtimeExecutable = "node",
        runtimeArgs = {
          "./node_modules/jest/bin/jest.js",
          "--runInBand",
        },
        rootPath = "${workspaceFolder}",
        cwd = "${workspaceFolder}",
        console = "integratedTerminal",
        internalConsoleOptions = "neverOpen"
      }
    }
  end
end

return M

I've tried building both nvim-dap-vscode-js and vscode-js-debug with specific versions and latest commit.

Any help will be much appreciated

Tiseno commented 1 year ago

This is because the vscode-js-debug have changed in the last release. This plugin assumes it will write the port on stdout but now it writes "Debug server listening at 127.0.0.1:8123" instead.

Seems to me like a refactor in vscode-js-debug changed the executable to src/dapDebugServer.ts, which prints the new message (previously this line i believe). I have a hard time testing this out as mason is broken and doesn't let me install the previous version.

Edit: Here is the change in executable that is installed: https://github.com/mason-org/mason-registry/commit/425b3612fa9d3b844238b575ad712572191a2a58

Mason for some switched to use the new dapDebugServer for 1.77.1 in the minor bump, which I think still is in a WIP state.

Tiseno commented 1 year ago

Finally got it working again, the new executable of vscode-js-debug is a dap compliant server, and thus we can configure it manually as an adapter in nvim-dap instead of using this plugin, as described here.

For me debugging node (using mason) it looks like this

require("dap").adapters["pwa-node"] = {
  type = "server",
  host = "localhost",
  port = "${port}",
  executable = {
    command = "js-debug-adapter", -- As I'm using mason, this will be in the path
    args = {"${port}"},
  }
}

for _, language in ipairs { "typescript", "javascript" } do
  require("dap").configurations[language] = {
    {
      type = "pwa-node",
      request = "attach",
      name = "Attach to node",
      processId = require("dap.utils").pick_process,
      cwd = "${workspaceFolder}",
    },
  }
end

I do not use debugging for Jest but hope this helps!

ChilloManiac commented 1 year ago

Thanks for you help - I seemed to have been confused while changing from using Mason and using microsoft/vscode-js-debug to install it.

What worked for me was not including the debug_cmd as i was installing it withou Mason.

So for anyone who comes looking, i:

  1. Installed microsoft/vscode-js-debug v.1.74.1
  2. Point to installation directory
  3. Don't set a debug_cmd

Thanks for the feedback, you helped me in finding my error

Final config if needed:

local M = {
  "mfussenegger/nvim-dap",
  dependencies = {
    { "rcarriga/nvim-dap-ui" },
    {
      "mxsdev/nvim-dap-vscode-js",
      tag = "v1.1.0",
    },
    {
      "microsoft/vscode-js-debug",
      tag = "v1.74.1",
      build =
      "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
    },
  },
  keys = {
    -- Snippet
  }
}

M.config = function()
  require('dap-vscode-js').setup({
    debugger_path = vim.fn.stdpath('data') .. '/lazy/vscode-js-debug',
    adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
  })

  local dap = require('dap')

  -- language config
  for _, language in ipairs({ 'typescript', 'javascript' }) do
    dap.configurations[language] = {
      {
        type = "pwa-node",
        request = "launch",
        name = "Debug Jest Tests",
        -- trace = true, -- include debugger info
        runtimeExecutable = "node",
        runtimeArgs = {
          "./node_modules/jest/bin/jest.js",
          "--runInBand",
          "${file}",
        },
        rootPath = "${workspaceFolder}",
        cwd = "${workspaceFolder}",
        console = "integratedTerminal",
        internalConsoleOptions = "neverOpen",
        port = 8123,
      }
    }
  end
end

return M
nsoufian commented 1 year ago

@Tiseno i'm still having the same issue using pwa-chrome addapter, any solution for this ?

Tiseno commented 1 year ago

Not from me, I do not debug chrome, but if vscode-js-debug dapDebugServer can connect to chrome and you launch chrome with debugging port enabled the solution should be the same as for a node process I would think; manually configure your pwa-chrome adapter and skip this plugin.

This plugin (as i understand it, without having dug too far) was just a compatibility layer for vscode-js-debug as it did not comply to the DAP. But now that it does, it seems obsolete.

Otherwise you would have to install an earlier version of vscode-js-debug as ChilloManiac did.