Debugging¶
CodeArt debugs with nvim-dap and nvim-dap-ui. Both load the first time you use a debug key, so they cost nothing at startup. The debug adapters come from the language packs: turn on a pack and its debugger is installed and set up.
Quick start¶
- Open a file of a language whose pack is on (for example a Python file with
languages = { "python" }). - Put the cursor on a line and press
<F9>(or<leader>dbt) to set a breakpoint. - Press
<F5>(or<leader>dc) and pick a launch configuration. - Step with
<F10>(over),<F11>(into) and<S-F11>(out).<leader>duopens the DAP UI (scopes, breakpoints, call stack, watches, REPL and console);<leader>deevaluates the expression under the cursor or the selection. <leader>dtstops the session.<leader>dlruns the last configuration again.
All debug keys are on the Key maps page.
To debug a single test, put the cursor in it and press <leader>Td (:CodeArtTest debug): neotest runs it under the same adapter. See Testing.
Before 2.7 the function keys only worked after the key map plugin had loaded; now <F5>, <F9>, <F10>, <F11> and <S-F11> also load nvim-dap on their own.
Per language¶
| Pack | Adapter | Launch configurations |
|---|---|---|
python |
debugpy | Launch file; Launch file with arguments. Uses $VIRTUAL_ENV, $CONDA_PREFIX, ./.venv or ./venv when there is one |
web |
js-debug (pwa-node, also answers to node) |
Launch file (Node.js); Attach to a Node.js process |
lua |
local-lua-debugger | Launch file (Lua), run with luajit (or lua) |
go |
delve | Debug package; Debug file; Debug test (package) |
rust |
codelldb | Launch: asks for the program (target/debug/...). Run cargo build first. :RustLsp debuggables (rustaceanvim) lists the binaries and tests to debug without asking for a path |
cpp |
codelldb | Launch executable: asks for the program. Build with -g |
java |
java-debug through jdtls | Launch main class (jdtls finds the main class and class path). Open a .java file first so jdtls is running |
bash |
bash-debug-adapter | Launch file (set up by mason-nvim-dap) |
csharp |
netcoredbg | Launch: asks for the .dll (set up by mason-nvim-dap). Run dotnet build first |
php |
php-debug-adapter (Xdebug) | Listen for Xdebug (port 9003); Launch file (Xdebug). Needs the Xdebug extension in your PHP |
zig |
codelldb | Launch executable: asks for the program (zig-out/bin/...). Run zig build first |
ruby |
rdbg (the debug gem) | Launch file; Launch file with bundle exec; RSpec current file; Attach to rdbg (port 12345, for rdbg --open --port 12345) |
kotlin |
kotlin-debug-adapter | Launch main class (asks for it, for example com.example.AppKt); Attach (port 5005). Build with Gradle or Maven first |
powershell |
PowerShell Editor Services | Launch file; Launch file with arguments |
dart |
the SDK's debug adapter (dart debug_adapter, or flutter debug_adapter in a Flutter project) |
Launch file (Dart); Launch app (Flutter, lib/main.dart) |
elixir |
ElixirLS's debug adapter (mix_task) |
mix test; mix run |
mason-nvim-dap sets up adapters it knows about first (debugpy, delve, codelldb, bash, netcoredbg, php, kotlin, dart and elixir); a pack then only adds what is still missing.
Your own launch configurations¶
Add them in config.other_configs (it runs after everything else loads), or in a .vscode/launch.json in your project (nvim-dap reads it when you start a session). Configurations you set for a filetype are kept; packs never replace them.
M.config = {
other_configs = function()
vim.cmd("colorscheme enfocado")
local ok, dap = pcall(require, "dap")
if ok then
dap.configurations.python = {
{ type = "python", request = "launch", name = "Django", program = "${workspaceFolder}/manage.py", args = { "runserver", "--noreload" } },
}
end
end,
}
Build before debugging¶
Name a task in preLaunchTask and it runs before the debug session starts; the session starts only if the task succeeds. postDebugTask runs after the session ends. "${defaultBuildTask}" is the project's build task, the one :CodeArtBuild runs (CMake, Cargo, go build, dotnet build, zig build, ...); any other name is a task from <leader>R, such as "zig build" or "cmake build". The tasks run through overseer.nvim (see Running and building), so their output is in the task list (<leader>Rl).
In .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "codelldb",
"request": "launch",
"name": "Build and debug",
"program": "${workspaceFolder}/zig-out/bin/app",
"preLaunchTask": "${defaultBuildTask}"
}
]
}
Or in config.other_configs, with preLaunchTask = "${defaultBuildTask}" in the configuration. With disable_plugins.overseer = true, these fields are ignored.
Settings¶
| Setting | Default | Effect |
|---|---|---|
disable_plugins.nvim_dap |
false |
true turns off debugging and the debug keys |
disable_plugins.nvim_dap_ui |
false |
true turns off the DAP UI |
disable_plugins.mason_nvim_dap |
false |
true leaves all adapter setup to the packs |
config.dapui |
Options merged into require("dapui").setup() |
|
config.mason_dap_config |
Options merged into require("mason-nvim-dap").setup() |
Troubleshooting¶
- "Debug adapter didn't respond": the adapter is not installed or could not start. Run
:CodeArtLanguagesto see what is missing, and:lua require("dap").set_log_level("TRACE")then check:DapShowLog. - No configuration for the filetype: the pack for that language is not in
languages, or another plugin set an empty list. - macOS asks for permission, or codelldb hangs at launch: allow Terminal (or your terminal app) under System Settings → Privacy & Security → Developer Tools, or run
sudo DevToolsSecurity -enableonce.