diff --git a/lua/dapui/config/init.lua b/lua/dapui/config/init.lua index 32f09f0..fb936ff 100644 --- a/lua/dapui/config/init.lua +++ b/lua/dapui/config/init.lua @@ -117,12 +117,7 @@ local function dep_warning(message) vim.schedule(function() if not dep_warnings[message] then dep_warnings[message] = true - vim.notify(message, vim.log.levels.WARN, { - title = "nvim-dap-ui", - on_open = function(win) - vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown") - end, - }) + require("dapui.util").notify(message, vim.log.levels.WARN) end end) end diff --git a/lua/dapui/init.lua b/lua/dapui/init.lua index 58c4a3d..9772618 100644 --- a/lua/dapui/init.lua +++ b/lua/dapui/init.lua @@ -1,8 +1,11 @@ ---@tag nvim-dap-ui + +local dap = require("dap") local dapui = {} local windows = require("dapui.windows") local config = require("dapui.config") +local util = require("dapui.util") local ui_state ---@return Element @@ -78,12 +81,16 @@ local prev_expr = nil ---@field height integer: Fixed height of window ---@field enter boolean: Whether or not to enter the window after opening function dapui.eval(expr, settings) + if not dap.session() then + util.notify("No active debug session", vim.log.levels.WARN) + return + end settings = settings or {} if not expr then if vim.fn.mode() == "v" then local start = vim.fn.getpos("v") local finish = vim.fn.getpos(".") - local lines = require("dapui.util").get_selection(start, finish) + local lines = util.get_selection(start, finish) expr = table.concat(lines, "\n") else expr = expr or vim.fn.expand("") @@ -121,13 +128,9 @@ end local refresh_control_panel = function() end function dapui.setup(user_config) - local dap = require("dap") local render = require("dapui.render") if ui_state then - vim.notify("Setup called twice", vim.log.levels.DEBUG, { - title = "nvim-dap-ui", - icon = " ", - }) + util.notify("Setup called twice", vim.log.levels.DEBUG) end render.loop.clear() @@ -150,7 +153,7 @@ function dapui.setup(user_config) end end - if config.controls.enabled and config.controls.element ~= '' then + if config.controls.enabled and config.controls.element ~= "" then local buf_name = buf_name_map[config.controls.element] local group = vim.api.nvim_create_augroup("DAPUIControls", {}) @@ -351,8 +354,6 @@ function dapui.toggle(opts) refresh_control_panel() end -local dap = require("dap") - _G._dapui = { play = function() local session = dap.session() diff --git a/lua/dapui/render/canvas.lua b/lua/dapui/render/canvas.lua index 91bcf3f..9f70b36 100644 --- a/lua/dapui/render/canvas.lua +++ b/lua/dapui/render/canvas.lua @@ -233,7 +233,7 @@ function M._mapping(action) local line = vim.fn.line(".") local callbacks = _mappings[buffer][action][line] if not callbacks then - vim.notify("No " .. action .. " action for current line", vim.log.levels.INFO) + util.notify("No " .. action .. " action for current line", vim.log.levels.INFO) return end for _, callback in pairs(callbacks) do diff --git a/lua/dapui/state.lua b/lua/dapui/state.lua index 7be038b..94b8fc3 100644 --- a/lua/dapui/state.lua +++ b/lua/dapui/state.lua @@ -233,7 +233,7 @@ function UIState:set_variable(container_ref, variable, value) { expression = variable.evaluateName, value = value, frameId = frame_id }, function(err) if err then - vim.notify(util.format_error(err)) + util.notify(util.format_error(err)) end end ) @@ -243,12 +243,12 @@ function UIState:set_variable(container_ref, variable, value) { variablesReference = container_ref, name = variable.name, value = value }, function(err) if err then - vim.notify(util.format_error(err)) + util.notify(util.format_error(err)) end end ) else - vim.notify( + util.notify( "Debug server doesn't support setting " .. (variable.evaluateName or variable.name), vim.log.levels.WARN ) diff --git a/lua/dapui/util.lua b/lua/dapui/util.lua index e5b3da6..bb67d86 100644 --- a/lua/dapui/util.lua +++ b/lua/dapui/util.lua @@ -12,6 +12,20 @@ function M.round(num) end end +function M.notify(msg, level, opts) + return vim.notify( + msg, + level or vim.log.levels.INFO, + vim.tbl_extend("keep", opts or {}, { + title = "nvim-dap-ui", + icon = "", + on_open = function(win) + vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown") + end, + }) + ) +end + function M.is_uri(path) local scheme = path:match("^([a-z]+)://.*") if scheme then @@ -76,7 +90,7 @@ function M.jump_to_frame(frame, session, set_frame) return end if not response.body.content then - vim.notify("No source available for frame", vim.log.levels.WARN) + M.notify("No source available for frame", vim.log.levels.WARN) return end vim.api.nvim_buf_set_lines(buf, 0, 0, true, vim.split(response.body.content, "\n")) @@ -88,7 +102,7 @@ function M.jump_to_frame(frame, session, set_frame) end if not source.path then - vim.notify("No source available for frame", vim.log.levels.WARN) + M.notify("No source available for frame", vim.log.levels.WARN) end local path = source.path diff --git a/lua/dapui/windows/init.lua b/lua/dapui/windows/init.lua index 1523d41..60b7ba2 100644 --- a/lua/dapui/windows/init.lua +++ b/lua/dapui/windows/init.lua @@ -20,7 +20,7 @@ local function create_win_states(win_configs) win_state.init_size = win_state.size win_states[#win_states + 1] = win_state else - vim.notify("nvim-dap-ui: Element " .. win_state.id .. " does not exist", vim.log.levels.WARN) + util.notify("nvim-dap-ui: Element " .. win_state.id .. " does not exist", vim.log.levels.WARN) end end return win_states