nvim-dap-view
website·Indexed 30 days ago
https://igorlfs.github.io/nvim-dap-view/homeA modern debugging UI for Neovim (requires Neovim 0.11+) that provides a visual interface for the Debug Adapter Protocol (DAP). It includes features such as a control bar, custom views, disassembly view, dynamic layout management, and support for custom formatting and highlight groups.
What's inside nvim-dap-view
- The Debug Adapter Protocol (DAP) standardizes communication between a text editor and a debugger. It introduces 'debug adapters'—programs that act as intermediaries to make various debuggers comply with a common communication standard. This prevents editors from needing custom integrations for every individual debugger. Note that a debugger (e.g., lldb) and a debug adapter (e.g., codelldb) are distinct programs, although some modern debuggers (like gdb 14.0+) implement the protocol natively.
Restore nvim-dap-view state using Vim sessions
nvim-dap-view integrates with the native Vim session system to persist specific debugger state across sessions.
Restored Data:
- The currently selected view (section).
- The full state of watched expressions, including variable expansions.
Non-Restored (Ephemeral) Data:
- Active DAP sessions.
- Stack traces.
Optional Breakpoint Restoration: Breakpoints are not restored by nvim-dap-view itself. To restore breakpoints, use a plugin like
persistent-breakpoints.nvimor a session manager that supports breakpoint persistence (e.g.,possession.nvim).Understand nvim-dap-view core features
nvim-dap-viewprovides a set of integrated views and UI enhancements for debugging in Neovim:- Watches View: CRUD operations for user-defined expressions evaluated by the debug adapter.
- Threads View: List of threads and stack traces with the ability to jump to functions in the call stack and filter frames via Lua patterns.
- Breakpoints View: List of breakpoints with syntax highlighting (Treesitter/LSP) and navigation to breakpoint locations.
- Exceptions View: Control debugger stop behavior for exceptions.
- Scopes View: Inspect, expand, collapse, and set values of variables in scope.
- Sessions View: Switch between multiple debugging sessions (disabled by default).
- REPL & Console Views: Integration with the
nvim-dapREPL and terminal console. - Control Bar: A clickable button bar for session control (disabled by default).
- Virtual Text: Displays variable values inline using asynchronous Treesitter parsing (disabled by default).
- Hover: A keymap-driven window to inspect and modify variable states.
Install nvim-dap-view
To install
nvim-dap-view, use the following configuration.Requirements:
- Neovim 0.11+ (Note: Inline virtual text specifically requires 0.12+).
- A Nerd Font is recommended (soft requirement).
nvim-treesitteris required for virtual text functionality.
vim.pack.add({ { src = "https://github.com/igorlfs/nvim-dap-view", version = vim.version.range("1.*") }, })Define a debug adapter in nvim-dap
To use a debugger in Neovim, you must first define an adapter in yournvim-dapconfiguration. This tells the plugin how to interact with the adapter executable. You only need to define an adapter once. For example, to define thecodelldbadapter (used for C, C++, and Rust), you specify the adapter type as 'executable' and provide the command to run it.require("dap").adapters.codelldb = { type = "executable", command = "codelldb", -- or if not in $PATH: "/absolute/path/to/codelldb", -- On windows you may have to uncomment this: -- detached = false, }Override jump behavior manually in nvim-dap-view
To override your configuredswitchbufsettings for a single jump, press<C-w><CR>. This opens a list of all available switching options, allowing you to force a specific behavior for the current action.Configure nvim-dap-view settings
Thenvim-dap-viewplugin applies default configurations automatically upon loading, so no explicit setup call is required. To override defaults, userequire"dap-view".setup(opts). The provided options are deep-merged with the defaults, meaning you only need to specify the keys you wish to change.require("dap-view").setup({ -- Your overrides here })Create custom buttons for the nvim-dap-view Control Bar
You can add custom buttons to the control bar by defining them in the
winbar.controls.custom_buttonstable and then adding the button's key to thewinbar.controls.buttonslist.A custom button requires two methods:
render: A function that returns the string to display (e.g., an emoji or NerdFont glyph). It receives the focused session as a parameter.action: A function executed on click. It receives three arguments:clicks(number of clicks),button(the button clicked:l,r,m), andmodifiers(a list of pressed modifiers:cfor control,sfor shift,afor alt, andmfor meta).
return { winbar = { controls = { enabled = true, -- Add the custom button key ('fun') to the active buttons list buttons = { "play", "step_into", "fun" }, custom_buttons = { fun = { render = function(session) return "🎉" end, action = function(clicks, button, modifiers) vim.print("🎊") end, }, }, }, }, }Enable Disassembly View in nvim-dap-view
The Disassembly View is a custom view built on top ofnvim-dap-disasm. To use it, you must first install thenvim-dap-disasmplugin. Once installed, enable the view by adding thedisassemblykeyword to thewinbar.sectionstable in your configuration.return { winbar = { sections = { "disassembly", -- other sections }, }, }Configure nvim-dap-view for session restoration
To ensure nvim-dap-view successfully restores its state when using a session manager, the following configuration requirements must be met:
- Vim Session Options: The
'sessionoptions'setting must include the"global"flag. - Loading Strategy: nvim-dap-view must NOT be manually lazy loaded. Because the plugin handles its own lazy loading, adding an external lazy load wrapper may prevent the session restoration hook from triggering.
- Session Manager Compatibility: Ensure your session manager plugin uses native Vim sessions as its backbone rather than a custom implementation.
-- Ensure 'global' is in sessionoptions vim.opt.sessionoptions:append('global')- Vim Session Options: The
Start a debugging session in nvim-dap
To begin debugging, ensure your program is compiled with debug symbols. Follow these steps:
- Set a breakpoint using
:DapToggleBreakpoint(or a custom mapping) to prevent the program from finishing before you can inspect it. - Start the session using
:DapContinue. - Refer to
:help dap-user-commandsfor a full list of available commands.
- Set a breakpoint using
Register a custom view for plugin distribution
Plugin authors can use theregister_viewfunction to automatically load a custom view. This removes the requirement for end-users to manually define the view in their configuration files.