diff options
| author | kylo252 <[email protected]> | 2022-11-10 16:11:55 +0100 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-10 16:11:55 +0100 | 
| commit | 87cde2f6a7c1358ba327096c3f802dbe100a64ae (patch) | |
| tree | 59fe391a5bbf92811b0a09e63b5e8750ce369e79 /lua/lvim/core | |
| parent | 73d225fffb684379ada36cc34479edbc697bea36 (diff) | |
feat: configure dap logging (#3454)
Diffstat (limited to 'lua/lvim/core')
| -rw-r--r-- | lua/lvim/core/dap.lua | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/lua/lvim/core/dap.lua b/lua/lvim/core/dap.lua index ad0116b9..4accd5fc 100644 --- a/lua/lvim/core/dap.lua +++ b/lua/lvim/core/dap.lua @@ -22,8 +22,14 @@ M.config = function()        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 = "" }, @@ -99,6 +105,8 @@ M.setup = function()      U = { "<cmd>lua require'dapui'.toggle()<cr>", "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 @@ -123,6 +131,43 @@ M.setup_ui = 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 | 
