local utils = require("utils") local inlay_hints_handler = require("inlay_hints_handler") local is_debug_mode_active = false return { "mfussenegger/nvim-dap", dependencies = { { "rcarriga/nvim-dap-ui", opts = { controls = { enabled = false, }, layouts = { { elements = { { id = "watches", size = 0.5 }, { id = "stacks", size = 0.5 } }, position = "bottom", size = 15 } }, } }, -- Special adapters { "leoluz/nvim-dap-go", opts = {} }, { "nvim-neotest/nvim-nio", lazy = true }, { "LiadOz/nvim-dap-repl-highlights", opts = {} }, { "theHamsta/nvim-dap-virtual-text", opts = {} }, { "Weissle/persistent-breakpoints.nvim", opts = { load_breakpoints_event = { "BufReadPost" } } }, }, config = function() local dap = require("dap") local virtual_text = require("nvim-dap-virtual-text/virtual_text") local breakpoint_api = require("persistent-breakpoints.api") local stepping_keymaps = { { "", function() dap.step_over() end }, { "", function() dap.step_into() end }, { "", function() dap.step_out() end }, { "dc", function() local columns = vim.o.columns local lines = vim.o.lines require("dapui").float_element("console", { enter = true, title = "output", border = "rounded", position = "center", width = math.floor(columns * 0.8), height = math.floor(lines * 0.6), }) end }, } local dap_signs = { { "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } }, { "DapBreakpointRejected", { text = "🔵", texthl = "", linehl = "", numhl = "" } }, { "DapBreakpointCondition", { text = "🟥", texthl = "", linehl = "", numhl = "" } }, } for _, sign in ipairs(dap_signs) do vim.fn.sign_define(unpack(sign)) end local function enter_debug_mode() if is_debug_mode_active then return end utils.set_keymap_list(stepping_keymaps) is_debug_mode_active = true inlay_hints_handler.disable() require("dapui").open() end local function exit_debug_mode() if not is_debug_mode_active then return end utils.del_keymap_list(stepping_keymaps) is_debug_mode_active = false inlay_hints_handler.restore() virtual_text.clear_virtual_text() require("dapui").close() end for _, request in ipairs({ { "attach", enter_debug_mode }, { "launch", enter_debug_mode }, }) do dap.listeners.before[request[1]]["dapui_config"] = request[2] end for _, event in ipairs({ { "event_terminated", exit_debug_mode }, { "event_exited", exit_debug_mode }, }) do dap.listeners.after[event[1]]["dapui_config"] = event[2] end local function dap_stop() dap.terminate() dap.close() exit_debug_mode() end utils.set_keymap_list({ { "dr", dap.continue }, { "bt", breakpoint_api.toggle_breakpoint }, { "bc", breakpoint_api.set_conditional_breakpoint }, { "br", breakpoint_api.clear_all_breakpoints }, { "ds", dap_stop }, }) end, }