Screen Too Small

This course material requires a larger screen to properly display the terminal and editor interfaces.

Please use a tablet, laptop, or desktop computer for the best learning experience.

You can continue browsing, but the experience will be significantly limited.

23/25
Free Trial: 3 lessons remaining
Unlock Full Access

What is DAP?

Estimated time: 5 minutes

The debug adapter protocol has a very similar story to the language server protocol. It was developed by, you guessed it, Microsoft. And it was developed for... you guessed it.... VSCode.

DAP allows for a communication between editors and debuggers through a middleman called a Debug Adapter. Using Debug Adapters, A package called nvim-dap , and a debugger, we can achieve a wonderful debugging environment for Neovim.

Here's a brief overview of how DAP in Neovim works:

  1. DAP Client Integration: Neovim, with plugins like nvim-dap, acts as a DAP client. These plugins handle the integration and provide an interface within Neovim for debugging.
  2. Debug Adapter: A debug adapter is a separate program that translates the DAP messages between Neovim and the debugger for the specific programming language.
  3. Communication: Neovim sends DAP requests (like starting a debug session, setting breakpoints, or stepping through code) to the debug adapter over a communication channel (e.g., TCP or STDIO).
  4. Execution and Response: The debug adapter processes these requests, communicates with the actual debugger, and sends back responses (like current variable values, execution status, or error messages).
  5. User Interface: The plugin presents this information in Neovim, allowing users to control and observe the debugging process directly within the editor.

By leveraging DAP, Neovim can support a wide range of debugging tools and languages, enhancing its capabilities as a development environment.

Here is a flowchart of how DAP works with Neovim.

To get a debugging experience in our Neovim setup, we're going to want to install nvim-dap: https://github.com/mfussenegger/nvim-dap.

Lets create a new file in our configuration called debugging.lua (or name it however you want). in this file, we can return a simple lua table that looks like this:

return {
  "mfussenegger/nvim-dap"
}

next, we want to copy over some helpful keybindings from the API of nvim-dap in order to, you know, toggle breakpoints and whatnot. Here is the config after adding keybindings:

  config = function()
    require("dapui").setup()
      vim.keymap.set("n", "<Leader>dt", ":DapToggleBreakpoint<CR>")
      vim.keymap.set("n", "<Leader>dc", ":DapContinue<CR>")
      vim.keymap.set("n", "<Leader>dx", ":DapTerminate<CR>")
      vim.keymap.set("n", "<Leader>do", ":DapStepOver<CR>")
    end

Now quit and re-open neovim and it should install nvim-dap!

You've completed this lesson!

You completed this lesson less than a minute ago.