local M = {} M.config = function() lvim.builtin.dap = { active = true, on_config_done = nil, breakpoint = { text = lvim.icons.ui.Bug, texthl = "DiagnosticSignError", linehl = "", numhl = "", }, breakpoint_rejected = { text = lvim.icons.ui.Bug, texthl = "DiagnosticSignError", linehl = "", numhl = "", }, stopped = { text = lvim.icons.ui.BoldArrowRight, texthl = "DiagnosticSignWarn", linehl = "Visual", numhl = "DiagnosticSignWarn", }, log = { level = "info", }, ui = { auto_open = true, notify = { threshold = vim.log.levels.INFO, }, config = { expand_lines = true, icons = { expanded = "", collapsed = "", circular = "" }, mappings = { -- Use a table to apply multiple mappings expand = { "", "<2-LeftMouse>" }, open = "o", remove = "d", edit = "e", repl = "r", toggle = "t", }, layouts = { { elements = { { id = "scopes", size = 0.33 }, { id = "breakpoints", size = 0.17 }, { id = "stacks", size = 0.25 }, { id = "watches", size = 0.25 }, }, size = 0.33, position = "right", }, { elements = { { id = "repl", size = 0.45 }, { id = "console", size = 0.55 }, }, size = 0.27, position = "bottom", }, }, floating = { max_height = 0.9, max_width = 0.5, -- Floats will be treated as percentage of your screen. border = vim.g.border_chars, -- Border style. Can be 'single', 'double' or 'rounded' mappings = { close = { "q", "" }, }, }, }, }, } end M.setup = function() local status_ok, dap = pcall(require, "dap") if not status_ok then return end if lvim.use_icons then vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) vim.fn.sign_define("DapBreakpointRejected", lvim.builtin.dap.breakpoint_rejected) vim.fn.sign_define("DapStopped", lvim.builtin.dap.stopped) end lvim.builtin.which_key.mappings["d"] = { name = "Debug", t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, b = { "lua require'dap'.step_back()", "Step Back" }, c = { "lua require'dap'.continue()", "Continue" }, C = { "lua require'dap'.run_to_cursor()", "Run To Cursor" }, d = { "lua require'dap'.disconnect()", "Disconnect" }, g = { "lua require'dap'.session()", "Get Session" }, i = { "lua require'dap'.step_into()", "Step Into" }, o = { "lua require'dap'.step_over()", "Step Over" }, u = { "lua require'dap'.step_out()", "Step Out" }, p = { "lua require'dap'.pause()", "Pause" }, r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, s = { "lua require'dap'.continue()", "Start" }, q = { "lua require'dap'.close()", "Quit" }, U = { "lua require'dapui'.toggle()", "Toggle UI" }, } dap.set_log_level(lvim.builtin.dap.log.level) if lvim.builtin.dap.on_config_done then lvim.builtin.dap.on_config_done(dap) end end M.setup_ui = function() local status_ok, dap = pcall(require, "dap") if not status_ok then return end local dapui = require "dapui" dapui.setup(lvim.builtin.dap.ui.config) if lvim.builtin.dap.ui.auto_open then dap.listeners.after.event_initialized["dapui_config"] = function() dapui.open() end -- dap.listeners.before.event_terminated["dapui_config"] = function() -- dapui.close() -- end -- dap.listeners.before.event_exited["dapui_config"] = function() -- dapui.close() -- end end local Log = require "lvim.core.log" -- until rcarriga/nvim-dap-ui#164 is fixed local function notify_handler(msg, level, opts) if level >= lvim.builtin.dap.ui.notify.threshold then return vim.notify(msg, level, opts) end opts = vim.tbl_extend("keep", opts or {}, { title = "dap-ui", icon = "", on_open = function(win) vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown") end, }) -- vim_log_level can be omitted if level == nil then level = Log.levels["INFO"] elseif type(level) == "string" then level = Log.levels[(level):upper()] or Log.levels["INFO"] else -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5 level = level + 1 end msg = string.format("%s: %s", opts.title, msg) Log:add_entry(level, msg) end local dapui_ok, _ = xpcall(function() require("dapui.util").notify = notify_handler end, debug.traceback) if not dapui_ok then Log:debug "Unable to override dap-ui logging level" end end return M