ソースを参照

feat: configure dap logging (#3454)

kylo252 2 年 前
コミット
c1d4f5ef59
1 ファイル変更45 行追加0 行削除
  1. 45 0
      lua/lvim/core/dap.lua

+ 45 - 0
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