local map = core.misc.map local keymap_restore = {} --- make the default hover binding work for nvim-dap instead of lsp local function set_hover_bind() for _, buf in pairs(vim.api.nvim_list_bufs()) do local keymaps = vim.api.nvim_buf_get_keymap(buf, "n") for _, keymap in pairs(keymaps) do if keymap.lhs == "K" then table.insert(keymap_restore, keymap) vim.api.nvim_buf_del_keymap(buf, "n", "K") end end end map("n", "K", function() require("dap.ui.widgets").hover(nil, { border = vim.g.border_style }) end, { silent = true }) end --- revert the hover bind back to whatever it was local function unset_hover_bind() for _, keymap in pairs(keymap_restore) do if keymap.rhs then vim.api.nvim_buf_set_keymap(keymap.buffer, keymap.mode, keymap.lhs, keymap.rhs, { silent = keymap.silent == 1 }) elseif keymap.callback then vim.keymap.set(keymap.mode, keymap.lhs, keymap.callback, { buffer = keymap.buffer, silent = keymap.silent == 1 }) end end keymap_restore = {} end return { { "mfussenegger/nvim-dap", reqs = { "mason-org/mason.nvim", "nvim-telescope/telescope.nvim" }, deps = "theHamsta/nvim-dap-virtual-text", branch = "0.10.0", lazy = function(load) load:keymap("n", "ec") load:keymap("n", "el") load:keymap("n", "et") load:keymap("n", "eb") load:keymap("n", "e]") load:keymap("n", "e[") load:keymap("n", "er") load:keymap("n", "eR") end, load = function() local dap = require("dap") -- define codelldb dap.adapters.codelldb = { type = "executable", command = "codelldb" } -- define the c configuration for codelldb dap.configurations.c = { { name = "Launch file", type = "codelldb", request = "launch", program = function() return vim.fn.input("Path to executable: ", vim.fn.getcwd().."/", "file") end, cwd = "${workspaceFolder}", stopOnEntry = false } } -- and define them for cpp, zig, and rust dap.configurations.cpp = dap.configurations.c dap.configurations.zig = dap.configurations.c dap.configurations.rust = dap.configurations.c -- keybinds map("n", "ec", dap.continue, { desc = "dap continue" }) map("n", "el", dap.run_last, { desc = "dap run last" }) map("n", "et", function() dap.terminate() unset_hover_bind() end, { desc = "dap terminate " }) map("n", "eb", require("dap.breakpoints").toggle, { desc = "dap toggle breakpoint" }) map("n", "e]", dap.step_over, { desc = "dap step over" }) map("n", "e[", dap.step_back, { desc = "dap step back" }) map("n", "er", dap.repl.toggle, { desc = "dap repl toggle" }) map("n", "eR", dap.restart, { desc = "dap restart" }) -- events dap.listeners.after["event_initialized"]["me"] = set_hover_bind dap.listeners.after["event_terminated"]["me"] = unset_hover_bind end }, { "theHamsta/nvim-dap-virtual-text", reqs = { "nvim-treesitter/nvim-treesitter", "mfussenegger/nvim-dap" }, lazy = dep_short.cmd("DapVirtualTextToggle"), load = function() require("nvim-dap-virtual-text").setup { virt_text_pos = vim.fn.has("nvim-0.10") == 1 and "inline" or "eol", --- A callback that determines how a variable is displayed or whether it should be omitted --- @param variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable --- @param buf number --- @param stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame --- @param node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`) --- @param options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text --- @return string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed display_callback = function(variable, buf, stackframe, node, options) -- by default, strip out new line characters if options.virt_text_pos == "inline" then return " = "..variable.value:gsub("%s+", " ") else return variable.name.." = "..variable.value:gsub("%s+", " ") end end } end }, { "mfussenegger/nvim-dap-python", reqs = "mfussenegger/nvim-dap", lazy = dep_short.ft("python"), load = function() local debugpy = core.mason.get_pkg_path("debugpy", "/venv/bin/python3") require("dap-python").setup(debugpy) end } }