如何在neovim下为typescript配置DAP调试器?

Ste*_*ane 6 neovim

我正在尝试为应用程序配置DAP调试器。Neovimtypescript

我添加了DAP插件:

    use "mfussenegger/nvim-dap"
Run Code Online (Sandbox Code Playgroud)

我还有一个config.lua包含适配器和配置的文件:

      local status_ok, dap = pcall(require, "dap")
      if not status_ok then
        return
      end
      
      dap.adapters.chrome = {
        type = "executable",                                                                                                                                      
        command = "node",    
        args = {os.getenv("HOME") .. "/dev/dap-debugger/vscode-js-debug/out/src/debugServerMain.js", "45635"}
      }    
      dap.configurations.typescript = {    
        {    
        type = "chrome",    
        request = "attach",    
        program = "${file}",   
        debugServer = 45635,
        cwd = vim.fn.getcwd(),    
        sourceMaps = true,    
        protocol = "inspector",    
        port = 9222,    
        webRoot = "${workspaceFolder}"    
        }    
      }
Run Code Online (Sandbox Code Playgroud)

当我在 typescript 应用程序项目中的 nvim 下尝试使用以下命令启动调试器时:lua require'dap'.continue(),出现错误:

Debug adapter didn't respond. Either the adapter is slow (then wait and ignore this) or there is a problem with your adapter or `chrome` configuration. Check 
the logs for errors (:help dap.set_log_level)
Run Code Online (Sandbox Code Playgroud)

~/.cache/nvim/dap.logDAP日志没有显示错误:

    [ DEBUG ] 2022-04-12T08:49:37Z+0200 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:776 ] "Spawning debug adapter"    {
      args = { "/home/stephane/dev/dap-debugger/vscode-js-debug/out/src/debugServerMain.js", "45635" },
      command = "node",
      type = "executable"
    }
    [ DEBUG ] 2022-04-12T08:49:37Z+0200 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:965 ] "request"   {
      arguments = {
        adapterID = "nvim-dap",
        clientId = "neovim",
        clientname = "neovim",
        columnsStartAt1 = true,
        linesStartAt1 = true,
        locale = "en_US.UTF-8",
        pathFormat = "path",
        supportsRunInTerminalRequest = true,
        supportsVariableType = true
      },
      command = "initialize",
      seq = 0,
      type = "request"
    }
Run Code Online (Sandbox Code Playgroud)

我可以使用以下命令设置断点:

Debug adapter didn't respond. Either the adapter is slow (then wait and ignore this) or there is a problem with your adapter or `chrome` configuration. Check 
the logs for errors (:help dap.set_log_level)
Run Code Online (Sandbox Code Playgroud)

我还使用以下命令安装了VSCode Js 调试器:

    [ DEBUG ] 2022-04-12T08:49:37Z+0200 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:776 ] "Spawning debug adapter"    {
      args = { "/home/stephane/dev/dap-debugger/vscode-js-debug/out/src/debugServerMain.js", "45635" },
      command = "node",
      type = "executable"
    }
    [ DEBUG ] 2022-04-12T08:49:37Z+0200 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:965 ] "request"   {
      arguments = {
        adapterID = "nvim-dap",
        clientId = "neovim",
        clientname = "neovim",
        columnsStartAt1 = true,
        linesStartAt1 = true,
        locale = "en_US.UTF-8",
        pathFormat = "path",
        supportsRunInTerminalRequest = true,
        supportsVariableType = true
      },
      command = "initialize",
      seq = 0,
      type = "request"
    }
Run Code Online (Sandbox Code Playgroud)

我可以看到我的 Chrome 浏览器正在侦听该9222端口:

    lua require'dap'.toggle_breakpoint()
Run Code Online (Sandbox Code Playgroud)

如果我手动运行调试器,我可以看到它在给定的端口号上启动:

    git clone https://github.com/microsoft/vscode-js-debug
    cd vscode-js-debug/
    npm i
    gulp
Run Code Online (Sandbox Code Playgroud)

我上线了NVIM v0.7.0-dev

我的 Angular 应用程序已启动并响应正常。

更新:我尝试使用的调试器不符合 DAP 标准。我想我需要找到一个替代方案。

Ste*_*ane 5

VSCode Chrome 调试器已弃用,已被 VSCode JS 调试器取代。VSCode JS 调试器与所有浏览器兼容。但 VSCode JS 调试器不兼容 DAP。所以目前仍然使用 VSCode Chrome 调试器。

\n

安装调试器:

\n
git clone git@github.com:microsoft/vscode-chrome-debug.git\ncd vscode-chrome-debug\nnpm install\nnpm run build\n
Run Code Online (Sandbox Code Playgroud)\n

配置调试器:

\n
  local function configureDebuggerAngular(dap)    \n    dap.adapters.chrome = {    \n      -- executable: launch the remote debug adapter - server: connect to an already running debug adapter    \n      type = "executable",    \n      -- command to launch the debug adapter - used only on executable type    \n      command = "node",    \n      args = { os.getenv("HOME") .. "/.local/share/nvim/lsp-debuggers/vscode-chrome-debug/out/src/chromeDebug.js" }    \n    }    \n    -- The configuration must be named: typescript    \n    dap.configurations.typescript = {    \n      {    \n        name = "Debug (Attach) - Remote",    \n        type = "chrome",    \n        request = "attach",    \n        -- program = "${file}",    \n        -- cwd = vim.fn.getcwd(),    \n        sourceMaps = true,    \n        --      reAttach = true,    \n        trace = true,    \n        -- protocol = "inspector",    \n        -- hostName = "127.0.0.1",    \n        port = 9222,    \n        webRoot = "${workspaceFolder}"    \n      }    \n    }    \n  end\n\n  local function configureDap()\n    local status_ok, dap = pcall(require, "dap")\n    if not status_ok then\n      print("The dap extension could not be loaded")\n      return\n    end\n  \n    dap.set_log_level("DEBUG")\n  \n    vim.highlight.create('DapBreakpoint', { ctermbg = 0, guifg = '#993939', guibg = '#31353f' }, false)\n    vim.highlight.create('DapLogPoint', { ctermbg = 0, guifg = '#61afef', guibg = '#31353f' }, false)\n    vim.highlight.create('DapStopped', { ctermbg = 0, guifg = '#98c379', guibg = '#31353f' }, false)\n  \n    vim.fn.sign_define('DapBreakpoint', { text = '\xef\x98\xae', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint',\n      numhl = 'DapBreakpoint' })\n    vim.fn.sign_define('DapBreakpointCondition',\n      { text = '\xef\xb3\x81', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })\n    vim.fn.sign_define('DapBreakpointRejected',\n      { text = '\xef\x81\xaa', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })\n    vim.fn.sign_define('DapLogPoint', { text = '\xef\x81\x9a', texthl = 'DapLogPoint', linehl = 'DapLogPoint', numhl = 'DapLogPoint' })\n    vim.fn.sign_define('DapStopped', { text = '\xef\x85\x84', texthl = 'DapStopped', linehl = 'DapStopped', numhl = 'DapStopped' })\n  \n    return dap\n  end\n\n  local function configure()\n    local dap = configureDap()\n  \n    if nil == dap then\n      print("The DAP core debugger could not be set")\n    end\n  \n    configureDebuggerAngular(dap)\n  end\n
Run Code Online (Sandbox Code Playgroud)\n