Debugging with nvim-dap

Debugging with nvim-dap

DAP — the Debug Adapter Protocol — is LSP’s sibling: one protocol, per-language adapters (Python’s is debugpy, installed via Mason), any editor.

The keymaps

The course config groups debugging under <leader>d:

KeysAction
<leader>dbtoggle a breakpoint on this line
<leader>dccontinue / start the session
<leader>dostep over one line
<leader>dtterminate the session

The loop

  1. Put the cursor on the line where the interesting thing happens and press <leader>db. The line is now a tripwire.
  2. <leader>dc, choose how to launch (for a script: run the current file), and the program runs — then stops right on your line.
  3. The dap-ui panels show every local variable, live: arguments, loop state, the call stack. Step with <leader>do and watch values update.
  4. <leader>dt shuts the session down.

No print statements were harmed. The state you used to reconstruct by logging is simply on screen.

Requirements

  • nvim-dap + nvim-dap-ui plugins (both in the course config)
  • a language adapter — Mason installs debugpy for Python