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.

24/25
Free Trial: 4 lessons remaining
Unlock Full Access

A UI for Debugging

Estimated time: 5 minutes

We now have nvim-dap installed and a debugging.lua configuration file for holding our debugging configuration. But, we are missing something really powerful, an actual UI for us to use when debugging! On its own, nvim-dap will work just fine without a UI. But its really difficult to get accustomed to, so I highly recommend installing nvim-dap-ui

here is a link to the repo: https://github.com/rcarriga/nvim-dap-ui

We want to add nvim-dap-ui as a dependency in our debugging.lua file. We also want to make sure we initialize nvim-dap-ui by adding:

require("dapui").setup()

but wait, there's more.

nvim-dap-ui 's documentation has an amazing example we can use to automatically open and close our DAP UI during certain debugging events. If we take a look at the repo listed above, we can see these lines being used in an example:

dap.listeners.before.attach.dapui_config = function()
  dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
  dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
  dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
  dapui.close()
end

The ☝️code reads pretty straightforward. When certain events happen during debugging (like hitting a breakpoint, etc...), nvim-dap-ui will open its UI so we can see our debugging frames automatically. This is extremely helpful, so we should add it to our configuration.

Now our configuration should look like this:

return {
    "mfussenegger/nvim-dap",
    dependencies = {
        "rcarriga/nvim-dap-ui",
    },
    config = function()
    require("dapui").setup()
        local dap, dapui = require("dap"), require("dapui")

        dap.listeners.before.attach.dapui_config = function()
            dapui.open()
        end
        dap.listeners.before.launch.dapui_config = function()
            dapui.open()
        end
        dap.listeners.before.event_terminated.dapui_config = function()
            dapui.close()
        end
        dap.listeners.before.event_exited.dapui_config = function()
            dapui.close()
        end

        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,
}

This sets us up nicely for our debugging environment with nvim dap! Now all we have to do is add a debugger and hook it up into this configuration, which is exactly what we're going to do in the next section.

You've completed this lesson!

You completed this lesson less than a minute ago.