我正在寻找设置 nvim-dap 并按照使用 Python 和 JavaScript 实现它的说明进行操作,这看起来非常简单,但我似乎无法让它工作。这是我的插件:
-- Debugger
use("mfussenegger/nvim-dap")
use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"} }
use('theHamsta/nvim-dap-virtual-text')
-- Python
use ('mfussenegger/nvim-dap-python')
require('dap-python').setup('~/.virtualenvs/debugpy/bin/python')
-- JavaScript
use { "mxsdev/nvim-dap-vscode-js", requires = {"mfussenegger/nvim-dap"} }
use {
"microsoft/vscode-js-debug",
opt = true,
run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
}
require("dap-vscode-js").setup({
-- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
-- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
-- debugger_cmd = { "js-debug-adapter" }, -- Command to use to launch the debug server. Takes precedence over `node_path` and `debugger_path`.
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }, -- which adapters to register in nvim-dap
-- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
-- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
-- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})
for _, language in ipairs({ "typescript", "javascript" }) do
require("dap").configurations[language] = {
{
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "${file}",
cwd = "${workspaceFolder}",
},
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require'dap.utils'.pick_process,
cwd = "${workspaceFolder}",
}
}
}
end
按照 nvim-dap-python 自述文件中的指示,我还在
~/.virtualenvs
下设置了一个专用的虚拟环境。
当我转到 Python 或 JS 文件并运行
:lua require('dap').continue()
时,我得到响应
No configuration found for 'python/javascript'. You need to add configs to 'dap.configurations.python/javascript
我对 dap-python 和 dap-vscode-js 插件的理解是,它们配置它,所以你不必这样做。我还尝试从 :help dap-configuration 添加示例配置,但它似乎不起作用。
当我获取 packer.lua 文件时,我也收到错误:
[packer.nvim] [ERROR 10:50:48] packer.lua:1022: Failure running setup function: "...ite/pack/packer
/start/nvim-dap-python/lua/dap-python.lua:96: nvim-dap is required to use dap-python"
我不确定什么会导致这个问题,因为 nvim-dap 已经安装了。
这是我的 neovim-config 存储库的链接:https://github.com/samcurteis/neovim-config/tree/main
快速总结:
我尝试按照 nvim-dap、nvim-dap-ui、nvim-dap-python 和 dap-vscode-js 上的说明设置插件。我还尝试手动配置 dap.configuration 但没有成功。当我运行
:lua require('dap').continue()
时,我期望调试器能够启动,但它没有启动。
我刚刚创建了有关如何使用 Python 调试器解决问题并使其正常工作的视频。这很简单,我在这里展示了所有内容https://www.youtube.com/watch?v=8urgm9LZI08
但基本上,你需要在 init.lua 中添加几个插件,然后调用 setup() 函数设置默认值,然后创建一些用于打开 dapui 的快捷方式并安装 debugpy。
Here are data from my init.lua
install plugins
--DAP debugger
{ 'mfussenegger/nvim-dap' },
{ 'theHamsta/nvim-dap-virtual-text' },
{ 'nvim-neotest/nvim-nio' },
{ 'rcarriga/nvim-dap-ui' },
{ 'mfussenegger/nvim-dap-python'},
-- debugger end
call setup functions
require('dap-python').setup()
require('dapui').setup()
install also debugpy
and shortcuts
vim.api.nvim_set_keymap("n", "<leader>db", ":DapToggleBreakpoint<CR>", {noremap=true})
vim.api.nvim_set_keymap("n", "<leader>dc", ":DapContinue<CR>", {noremap=true})
vim.api.nvim_set_keymap('n', '<leader>do', ':lua require("dapui").open()<CR>', { noremap = true, silent = true })
所以你的问题是因为你错过了 require('dap-python').setup() 的 setup() 调用 require('dapui').setup()
检查一下,希望这会对您有所帮助。一切也都在我的视频中。