如何在Neovim下为打字稿配置DAP调试器?

发布于 2025-01-20 13:14:31 字数 3453 浏览 2 评论 0原文

我正在尝试在neovim中为typesscript 应用程序配置dap调试器。

我添加了DAP插件:

    use "mfussenegger/nvim-dap"

我也有一个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}"    
        }    
      }

何时在我的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)

但是〜/.cache/nvim/dap.log dap log显示没有错误

    [ 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"
    }

。命令:

    lua require'dap'.toggle_breakpoint()

我还安装了 vscode js debugger 带有以下命令:

    git clone https://github.com/microsoft/vscode-js-debug
    cd vscode-js-debug/
    npm i
    gulp

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

    chrome    208069        stephane  118u  IPv4 1193769      0t0  TCP 127.0.0.1:9222 (LISTEN)

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

    09:16 $ node ~/dev/dap-debugger/vscode-js-debug/out/src/debugServerMain.js 45635
    Debug server listening at 45635

我在nvim v0.7.0-dev

我的Angular应用程序已开始,并做出了正确的响应。

更新:我要使用的调试器是。我想我需要找到另一种选择。

I'm trying to configure the DAP debugger in Neovim for a typescript application.

I added the DAP plugin:

    use "mfussenegger/nvim-dap"

I also have a config.lua file containing the adapter and configuration:

      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}"    
        }    
      }

When, under nvim in my typescript application project, I try to start the debugger with the :lua require'dap'.continue() command, I get the error:

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)

But the ~/.cache/nvim/dap.log DAP log shows no error:

    [ 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"
    }

I can set breakpoints with the command:

    lua require'dap'.toggle_breakpoint()

I also installed the VSCode Js debugger with the following commands:

    git clone https://github.com/microsoft/vscode-js-debug
    cd vscode-js-debug/
    npm i
    gulp

I can see that my Chrome browser is listening on the 9222 port:

    chrome    208069        stephane  118u  IPv4 1193769      0t0  TCP 127.0.0.1:9222 (LISTEN)

If I run the debugger manually, I can see it starts on the given port number:

    09:16 $ node ~/dev/dap-debugger/vscode-js-debug/out/src/debugServerMain.js 45635
    Debug server listening at 45635

I'm on NVIM v0.7.0-dev

My Angular application is started and responds all right.

UPDATE: The debugger I was trying to use is not on DAP standard. I guess I need to find an alternative.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

a√萤火虫的光℡ 2025-01-27 13:14:31

Vscode Chrome调试器已弃用,已被VSCODE JS调试器取代。 VSCODE JS调试器与所有浏览器兼容。但是VSCODE JS调试器不符合DAP。因此,目前仍在使用Vscode Chrome调试器。

安装调试器:

git clone [email protected]:microsoft/vscode-chrome-debug.git
cd vscode-chrome-debug
npm install
npm run build

配置调试器:

  local function configureDebuggerAngular(dap)    
    dap.adapters.chrome = {    
      -- executable: launch the remote debug adapter - server: connect to an already running debug adapter    
      type = "executable",    
      -- command to launch the debug adapter - used only on executable type    
      command = "node",    
      args = { os.getenv("HOME") .. "/.local/share/nvim/lsp-debuggers/vscode-chrome-debug/out/src/chromeDebug.js" }    
    }    
    -- The configuration must be named: typescript    
    dap.configurations.typescript = {    
      {    
        name = "Debug (Attach) - Remote",    
        type = "chrome",    
        request = "attach",    
        -- program = "${file}",    
        -- cwd = vim.fn.getcwd(),    
        sourceMaps = true,    
        --      reAttach = true,    
        trace = true,    
        -- protocol = "inspector",    
        -- hostName = "127.0.0.1",    
        port = 9222,    
        webRoot = "${workspaceFolder}"    
      }    
    }    
  end

  local function configureDap()
    local status_ok, dap = pcall(require, "dap")
    if not status_ok then
      print("The dap extension could not be loaded")
      return
    end
  
    dap.set_log_level("DEBUG")
  
    vim.highlight.create('DapBreakpoint', { ctermbg = 0, guifg = '#993939', guibg = '#31353f' }, false)
    vim.highlight.create('DapLogPoint', { ctermbg = 0, guifg = '#61afef', guibg = '#31353f' }, false)
    vim.highlight.create('DapStopped', { ctermbg = 0, guifg = '#98c379', guibg = '#31353f' }, false)
  
    vim.fn.sign_define('DapBreakpoint', { text = '', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint',
      numhl = 'DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointCondition',
      { text = 'ﳁ', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointRejected',
      { text = '', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })
    vim.fn.sign_define('DapLogPoint', { text = '', texthl = 'DapLogPoint', linehl = 'DapLogPoint', numhl = 'DapLogPoint' })
    vim.fn.sign_define('DapStopped', { text = '', texthl = 'DapStopped', linehl = 'DapStopped', numhl = 'DapStopped' })
  
    return dap
  end

  local function configure()
    local dap = configureDap()
  
    if nil == dap then
      print("The DAP core debugger could not be set")
    end
  
    configureDebuggerAngular(dap)
  end

The VSCode Chrome debugger is deprecated and has been replaced by the VSCode JS debugger. The VSCode JS debugger is compatible with all browsers. But the VSCode JS debugger is not DAP compliant. So the VSCode Chrome debugger is still being used for now.

Installing the debugger:

git clone [email protected]:microsoft/vscode-chrome-debug.git
cd vscode-chrome-debug
npm install
npm run build

Configuring the debugger:

  local function configureDebuggerAngular(dap)    
    dap.adapters.chrome = {    
      -- executable: launch the remote debug adapter - server: connect to an already running debug adapter    
      type = "executable",    
      -- command to launch the debug adapter - used only on executable type    
      command = "node",    
      args = { os.getenv("HOME") .. "/.local/share/nvim/lsp-debuggers/vscode-chrome-debug/out/src/chromeDebug.js" }    
    }    
    -- The configuration must be named: typescript    
    dap.configurations.typescript = {    
      {    
        name = "Debug (Attach) - Remote",    
        type = "chrome",    
        request = "attach",    
        -- program = "${file}",    
        -- cwd = vim.fn.getcwd(),    
        sourceMaps = true,    
        --      reAttach = true,    
        trace = true,    
        -- protocol = "inspector",    
        -- hostName = "127.0.0.1",    
        port = 9222,    
        webRoot = "${workspaceFolder}"    
      }    
    }    
  end

  local function configureDap()
    local status_ok, dap = pcall(require, "dap")
    if not status_ok then
      print("The dap extension could not be loaded")
      return
    end
  
    dap.set_log_level("DEBUG")
  
    vim.highlight.create('DapBreakpoint', { ctermbg = 0, guifg = '#993939', guibg = '#31353f' }, false)
    vim.highlight.create('DapLogPoint', { ctermbg = 0, guifg = '#61afef', guibg = '#31353f' }, false)
    vim.highlight.create('DapStopped', { ctermbg = 0, guifg = '#98c379', guibg = '#31353f' }, false)
  
    vim.fn.sign_define('DapBreakpoint', { text = '', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint',
      numhl = 'DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointCondition',
      { text = 'ﳁ', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointRejected',
      { text = '', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })
    vim.fn.sign_define('DapLogPoint', { text = '', texthl = 'DapLogPoint', linehl = 'DapLogPoint', numhl = 'DapLogPoint' })
    vim.fn.sign_define('DapStopped', { text = '', texthl = 'DapStopped', linehl = 'DapStopped', numhl = 'DapStopped' })
  
    return dap
  end

  local function configure()
    local dap = configureDap()
  
    if nil == dap then
      print("The DAP core debugger could not be set")
    end
  
    configureDebuggerAngular(dap)
  end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文