I'm looking to set up nvim-dap and followed the instructions for implementing it with Python and JavaScript, which seem very straightforward, but I can't seem to get it working. Here are my plugins:
-- 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
As Instructed in the nvim-dap-python readme I also set up a dedicated virtual environment under ~/.virtualenvs
.
When I go to a Python or JS file and run :lua require('dap').continue()
, I get the response
No configuration found for 'python/javascript'. You need to add configs to 'dap.configurations.python/javascript
My understanding of the dap-python and dap-vscode-js plugins is that they configure it so you don't have to. I also tried adding an example configuration from :help dap-configuration, but it didn't seem to work.
When I source my packer.lua file I also get an error:
[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"
I'm not sure what would cause this since nvim-dap is already installed.
Here's a link to my neovim-config repo: https://github.com/samcurteis/neovim-config/tree/main
Quick summary:
I tried setting up the plugins as per the instructions on nvim-dap, nvim-dap-ui, nvim-dap-python and dap-vscode-js. I also attempted to manually configure the dap.configuration without success. When I ran :lua require('dap').continue()
, I expected the debugger to launch but it doesn't.
I have just created video about how I solved problem with debugger for Python and make it working. It is simple and I show everything here https://www.youtube.com/watch?v=8urgm9LZI08
But basically, you need to add couple of plugins into init.lua, then call setup() function to set default values, then create few shortcuts for opening dapui and install also 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 })
So your problem is cause you are missing that setup() call for require('dap-python').setup() require('dapui').setup()
Check this and I hope this will help you. Also all is on my video as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With