diff options
Diffstat (limited to 'home/nvim/plugins/dap.lua')
| -rw-r--r-- | home/nvim/plugins/dap.lua | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/home/nvim/plugins/dap.lua b/home/nvim/plugins/dap.lua new file mode 100644 index 0000000..c20ae36 --- /dev/null +++ b/home/nvim/plugins/dap.lua @@ -0,0 +1,147 @@ +-- Store DAP configuration in a function to load on demand +local function setup_dap() + local dap = require("dap") + local dapview = require("dap-view") + local dapvt = require("nvim-dap-virtual-text") + + dapview.setup({}) + + dapvt.setup { + enabled = true, + enabled_commands = true, + highlight_changed_variables = true, + highlight_new_as_changed = false, + show_stop_reason = true, + commented = false, + only_first_definition = true, + all_references = false, + clear_on_continue = false, + display_callback = function(variable, buf, stackframe, node, options) + if options.virt_text_pos == "inline" then + return " = " .. variable.value:gsub("%s+", " ") + else + return variable.name .. " = " .. variable.value:gsub("%s+", " ") + end + end, + all_frames = true, + virt_lines = true, + virt_text_win_col = nil, + } + + -- === PYTHON === + dap.adapters.python = { + type = "executable", + command = "python", + args = { "-m", "debugpy.adapter" }, + } + dap.configurations.python = { + { + type = "python", + request = "launch", + name = "Launch file", + program = "${file}", + console = "integratedTerminal", + justMyCode = true, + }, + { + type = "python", + request = "attach", + name = "Attach to process", + connect = { host = "127.0.0.1", port = 5678 }, + }, + } + + -- === RUST === + dap.adapters.lldb = { + type = "executable", + command = "lldb-dap", + name = "lldb", + } + dap.configurations.rust = { + { + name = "Launch (LLDB)", + type = "lldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = {}, + runInTerminal = false, + }, + { + name = "Attach to process (LLDB)", + type = "lldb", + request = "attach", + pid = require("dap.utils").pick_process, + args = {}, + }, + } + + -- === GO === + dap.adapters.go = { + type = "executable", + command = "dlv", + args = { "dap" }, + } + dap.configurations.go = { + { type = "go", name = "Debug main.go", request = "launch", program = "${file}" }, + { type = "go", name = "Debug package", request = "launch", program = "${workspaceFolder}" }, + { type = "go", name = "Attach to process", request = "attach", processId = require("dap.utils").pick_process }, + } + + -- === EVENT LISTENERS === + dap.listeners.after.event_initialized["dapview_config"] = function() dapview.open() end + dap.listeners.before.event_terminated["dapview_config"] = function() dapview.close() end + dap.listeners.before.event_exited["dapview_config"] = function() dapview.close() end +end + +-- Define custom commands to trigger DAP setup +local function define_dap_commands() + vim.api.nvim_create_user_command("DapContinue", function() + setup_dap() + require("dap").continue() + end, {}) + vim.api.nvim_create_user_command("DapToggleBreakpoint", function() + setup_dap() + require("dap").toggle_breakpoint() + end, {}) + vim.api.nvim_create_user_command("DapStepOver", function() + setup_dap() + require("dap").step_over() + end, {}) + vim.api.nvim_create_user_command("DapStepInto", function() + setup_dap() + require("dap").step_into() + end, {}) + vim.api.nvim_create_user_command("DapStepOut", function() + setup_dap() + require("dap").step_out() + end, {}) + vim.api.nvim_create_user_command("DapTerminate", function() + setup_dap() + require("dap").terminate() + end, {}) +end + +-- Create autocommand group for DAP +local augroup = vim.api.nvim_create_augroup("DapLazyLoad", { clear = true }) + +-- Load DAP on filetypes +vim.api.nvim_create_autocmd("FileType", { + group = augroup, + pattern = { "python", "rust", "go" }, + callback = function() + define_dap_commands() + end, +}) + +-- Load DAP on specific commands +vim.api.nvim_create_autocmd("CmdUndefined", { + group = augroup, + pattern = { "DapContinue", "DapToggleBreakpoint", "DapStepOver", "DapStepInto", "DapStepOut", "DapTerminate" }, + callback = function() + define_dap_commands() + end, +}) |
