首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何为类型记录配置新版本下的DAP调试器?

如何为类型记录配置新版本下的DAP调试器?
EN

Stack Overflow用户
提问于 2022-04-09 16:44:09
回答 1查看 5.2K关注 0票数 3

我试图在Neovim中为typescript应用程序配置typescript调试器。

我添加了DAP插件:

代码语言:javascript
运行
复制
    use "mfussenegger/nvim-dap"

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

代码语言:javascript
运行
复制
      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}"    
        }    
      }

在我的类型记录应用程序项目中的nvim下,当我尝试使用:lua require'dap'.continue()命令启动调试器时,我会得到以下错误:

代码语言:javascript
运行
复制
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日志没有显示错误:

代码语言:javascript
运行
复制
    [ 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"
    }

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

代码语言:javascript
运行
复制
    lua require'dap'.toggle_breakpoint()

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

代码语言:javascript
运行
复制
    git clone https://github.com/microsoft/vscode-js-debug
    cd vscode-js-debug/
    npm i
    gulp

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

代码语言:javascript
运行
复制
    chrome    208069        stephane  118u  IPv4 1193769      0t0  TCP 127.0.0.1:9222 (LISTEN)

如果手动运行调试器,可以看到它从给定的端口号开始:

代码语言:javascript
运行
复制
    09:16 $ node ~/dev/dap-debugger/vscode-js-debug/out/src/debugServerMain.js 45635
    Debug server listening at 45635

我在NVIM v0.7.0-dev

我的角度应用程序已经启动并且反应正常。

更新:我试图使用的调试器是不符合DAP标准。我想我得另找个办法。

EN

回答 1

Stack Overflow用户

发布于 2022-08-20 14:32:35

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

安装调试器:

代码语言:javascript
运行
复制
git clone git@github.com:microsoft/vscode-chrome-debug.git
cd vscode-chrome-debug
npm install
npm run build

配置调试器:

代码语言:javascript
运行
复制
  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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71810002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档