Neovim for Beginners — Debugging using DAP
We walked through the configuration of the built-in LSP client in previous articles. For code debugging, it is a little bit tricky. As of this writing, there are 2 plugins that can be used for debugging.
In this article, we will go through thenvim-dap
plugin which is a debug adapter protocol client, or “debugger”, or “debug-frontend”. In a later article, we shall look at thevimspector
plugin.
We are going to
- Configure the
nvim-dap
plugin together with the UI/UX and language extensions. - Configure key mappings for debugging using
which-key.nvim
. - Configure debugging for Lua, Python, Go, and Rust.
- Configure the
rust-tools.nvim
plugin for Rust debugging.
This article is part of the Neovim for Beginners series.
The Neovim configuration files can be found in this repository.
The Basics
Neovim does not have a built-in DAP client. Instead, nvim-dap
acts as the DAP client (:h dap.txt
). Using a debug adapter we can
- Launch an application to debug
- Attach to running applications to debug them
- Set breakpoints and step through code
- Inspect the state of the application
A debug adapter is a facilitator between nvim-dap
(the client), and a
language-specific debugger.
To debug applications, we need to configure two things per language.
- A debug adapter (
:h dap-adapter
) - How to launch your application to debug, or how to attach to a running application (
:h dap-configuration
)
Setup
In the lua/plugins.lua
file, add the lines to install nvim-dap
and the extensions.