Skip to content

Commit

Permalink
refactor(log): simplify notification handling with helper function
Browse files Browse the repository at this point in the history
Introduced a `notify` helper function to call `vim.notify` with a
schedule. Updated `M.warn` and `M.inform` to use this helper,
reducing code duplication in `log.lua`.

This commit was co-authored by @PMassicotte
  • Loading branch information
she3o committed Oct 11, 2024
1 parent 538a8c5 commit 1934442
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lua/r/log.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
--- Helper function to call vim.notify() with scheduled execution
---@param msg string
---@param level number
---@param opts table
local function notify(msg, level, opts)
vim.schedule(function() vim.notify(msg, level, opts) end)
end

local M = {}

--- Call vim.notify() with a warning message
---@param msg string
M.warn = function(msg)
vim.schedule(
function() vim.notify(msg, vim.log.levels.WARN, { title = "R.nvim" }) end
)
end
M.warn = function(msg) notify(msg, vim.log.levels.WARN, { title = "R.nvim" }) end

--- Call vim.notify() with to inform a message
--- Call vim.notify() to inform a message
---@param msg string
M.inform = function(msg)
vim.schedule(
function()
vim.notify(
msg,
vim.log.levels.INFO,
{ title = "R.nvim", hide_from_history = true }
)
end
)
notify(msg, vim.log.levels.INFO, { title = "R.nvim", hide_from_history = true })
end

return M

0 comments on commit 1934442

Please sign in to comment.