diff options
author | Squibid <me@zacharyscheiman.com> | 2025-05-08 18:18:34 -0500 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2025-05-08 18:18:34 -0500 |
commit | 7430ebed8eab0364452a6cdcaa209f8a7288e44d (patch) | |
tree | cd80b99c41c4af92c7a130fe52ca462062697d22 /lua/conf/plugins/dap.lua | |
parent | 7c3289fded1f75f6e060f56bd06edc2a327744d9 (diff) | |
download | nvim-7430ebed8eab0364452a6cdcaa209f8a7288e44d.tar.gz nvim-7430ebed8eab0364452a6cdcaa209f8a7288e44d.tar.bz2 nvim-7430ebed8eab0364452a6cdcaa209f8a7288e44d.zip |
kitchen sink now don't support any version lower than 0.11.0 for lspv3.0
- dap now works for java and c
Diffstat (limited to 'lua/conf/plugins/dap.lua')
-rw-r--r-- | lua/conf/plugins/dap.lua | 90 |
1 files changed, 69 insertions, 21 deletions
diff --git a/lua/conf/plugins/dap.lua b/lua/conf/plugins/dap.lua index 7cb4903..5abe1b3 100644 --- a/lua/conf/plugins/dap.lua +++ b/lua/conf/plugins/dap.lua @@ -1,50 +1,98 @@ local misc = require("core.misc") local map = misc.map +--- select a program to execute +---@return thread coroutine containing the picker +local function select_program() + return coroutine.create(function(coro) + ---@diagnostic disable-next-line: param-type-mismatch + local entries = vim.fn.readdir(".", [[v:val !~ '^\.']]) + vim.ui.select(entries, { prompt = "Select the executable to run:" }, + function(choice) + coroutine.resume(coro, choice) + end) + end) +end + +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 + vim.keymap.set('n', 'K', require("dap.ui.widgets").hover, + { 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", requires = { - "williamboman/mason.nvim", - "nvim-telescope/telescope.nvim", + "mason-org/mason.nvim", + "nvim-telescope/telescope.nvim" }, - disable = not vim.fn.has("nvim-0.8.0"), - branch = "0.8.0", + disable = not vim.fn.has("nvim-0.9.5"), + branch = "0.10.0", function() - local dap = require("dap") - local codelldb_port = 13000 + -- define codelldb dap.adapters.codelldb = { - type = "server", - host = "127.0.0.1", - port = codelldb_port, - executable = { - command = require("mason-registry").get_package("codelldb"):get_install_path().."/codelldb", - args = { "--port", codelldb_port } - } + type = "executable", + command = "codelldb", } + -- define the c configuration for codelldb dap.configurations.c = { { - name = "LLDB: Launch", + name = "Launch file", type = "codelldb", request = "launch", - program = function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd().."/", "file") - end, + program = select_program, + cwd = "${workspaceFolder}", - stopOnEntry = false, - args = {}, - console = "integratedTerminal" + 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", dap.terminate, { desc = "dap terminate " }) + 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 } |