Debugging with DAP

There comes a point in every developer's journey where print statements stop being enough. When you need to pause execution, inspect variables at a specific moment, or step through a complex code path line by line, a real debugger is indispensable. The Debug Adapter Protocol brings that full debugging experience into Neovim, so you no longer have to leave your editor or fall back to a separate IDE when things get complicated.

The Debug Adapter Protocol (DAP) brings IDE-level debugging to Neovim -- breakpoints, stepping through code, inspecting variables, and more. Like LSP standardizes language features (see LSP -- Language Server Protocol), DAP standardizes debugging.

What you'll learn in this chapter:

  • Understand the Debug Adapter Protocol and how it connects Neovim to language-specific debuggers

  • Install and configure nvim-dap with Mason for automatic debug adapter management

  • Set breakpoints, step through code, and inspect variables using the DAP UI

  • Configure language-specific debug adapters for Python, Go, and JavaScript/TypeScript

  • Use the REPL and watch expressions to evaluate code during a debugging session

What is DAP?

┌──────────┐         ┌───────────────────┐
│  Neovim  │ ◄─DAP─► │  Debug Adapter    │
│ (client) │         │  (debugpy, delve, │
│          │         │   node-debug, etc.)│
└──────────┘         └───────────────────┘

DAP provides:

  • Breakpoints — pause execution at specific lines

  • Step controls — step over, step into, step out, continue

  • Variable inspection — see local and global variables

  • Watch expressions — monitor specific expressions

  • Call stack — see the function call hierarchy

  • REPL — evaluate expressions during debugging

Setup

The DAP configuration below uses Lua (see Neovim with Lua for Lua configuration basics) and Mason for automatic adapter installation.

Language-Specific Configuration

Python

Go

JavaScript / TypeScript

DAP Keybindings Reference

Key
Action

F5

Start / Continue

F10

Step Over

F11

Step Into

F12

Step Out

<leader>db

Toggle breakpoint

<leader>dB

Conditional breakpoint

<leader>dr

Open REPL

<leader>du

Toggle debug UI

<leader>dl

Re-run last debug session

Debug UI Layout

When debugging, nvim-dap-ui opens panels showing:

Tip: Install nvim-dap-virtual-textarrow-up-right to see variable values inline next to the code as you debug.

Summary

The Debug Adapter Protocol brings full-featured debugging to Neovim, letting you set breakpoints, step through execution, inspect variables, and evaluate expressions without switching to a separate IDE. With nvim-dap, nvim-dap-ui, and Mason handling adapter installation, you get a portable debugging setup that works across Python, Go, JavaScript, and many other languages.

Key takeaways:

  • DAP is to debugging what LSP is to language features: a protocol that standardizes communication between Neovim and language-specific debug adapters.

  • nvim-dap-ui automatically opens and closes debug panels (variables, breakpoints, REPL, call stack) when a debug session starts and stops.

  • Mason can automatically install debug adapters (debugpy, delve, js-debug-adapter), eliminating manual setup.

  • The function keys (F5, F10, F11, F12) provide familiar step controls, while <leader>db toggles breakpoints at the current line.

Exercises

  1. Set a breakpoint and start debugging -- Open a simple script in a supported language, set a breakpoint on a line of interest, and start a debug session.

  2. Step through code execution -- With a debug session paused at a breakpoint, practice stepping over, into, and out of function calls.

  3. Inspect variables and evaluate expressions -- During a paused debug session, examine local variables in the DAP UI and use the REPL to evaluate custom expressions.

  4. Set a conditional breakpoint -- Set a breakpoint that only pauses execution when a specific condition is met, such as a variable reaching a certain value.

  5. Re-run the last debug session -- After completing a debug session, quickly re-launch it with the same configuration without re-selecting options.

Last updated

Was this helpful?