Files
nvim/lua/conf/plugins/dap.lua
Squibid 7c96b43098 kitchen sink...
just gonna put the changes that I can remember making here:
 - replace blink with native completion (omnifunc)
 - remove some unneeded plugins
 - add a misc function for making sure complex bindings don't cause
   flickering
 - remove some stale snippets
 - remove folding (I don't find myself folding that often)
2025-08-02 11:25:38 -04:00

142 lines
4.8 KiB
Lua

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", "<leader>ec")
load:keymap("n", "<leader>el")
load:keymap("n", "<leader>et")
load:keymap("n", "<leader>eb")
load:keymap("n", "<leader>e]")
load:keymap("n", "<leader>e[")
load:keymap("n", "<leader>er")
load:keymap("n", "<leader>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", "<leader>ec", dap.continue, { desc = "dap continue" })
map("n", "<leader>el", dap.run_last, { desc = "dap run last" })
map("n", "<leader>et", function()
dap.terminate()
unset_hover_bind()
end, { desc = "dap terminate " })
map("n", "<leader>eb", require("dap.breakpoints").toggle, {
desc = "dap toggle breakpoint"
})
map("n", "<leader>e]", dap.step_over, { desc = "dap step over" })
map("n", "<leader>e[", dap.step_back, { desc = "dap step back" })
map("n", "<leader>er", dap.repl.toggle, { desc = "dap repl toggle" })
map("n", "<leader>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
}
}