diff --git a/doc/mini-notify.txt b/doc/mini-notify.txt index 781c8647..c0b3036c 100644 --- a/doc/mini-notify.txt +++ b/doc/mini-notify.txt @@ -225,10 +225,9 @@ Default: 25. `MiniNotify.make_notify`({opts}) Make vim.notify wrapper -Calling this function creates an implementation of |vim.notify()| powered -by this module. General idea is that notification is shown right away (as -soon as safely possible, see |vim.schedule()|) and removed after a configurable -amount of time. +Calling this function creates an implementation of |vim.notify()| powered by +this module. General idea is to show notification as soon as safely possible +(see |vim.schedule_wrap()|) and remove it after a configurable amount of time. Examples: >lua diff --git a/lua/mini/notify.lua b/lua/mini/notify.lua index 0499881c..ea00632b 100644 --- a/lua/mini/notify.lua +++ b/lua/mini/notify.lua @@ -241,10 +241,9 @@ MiniNotify.config = { --- Make vim.notify wrapper --- ---- Calling this function creates an implementation of |vim.notify()| powered ---- by this module. General idea is that notification is shown right away (as ---- soon as safely possible, see |vim.schedule()|) and removed after a configurable ---- amount of time. +--- Calling this function creates an implementation of |vim.notify()| powered by +--- this module. General idea is to show notification as soon as safely possible +--- (see |vim.schedule_wrap()|) and remove it after a configurable amount of time. --- --- Examples: >lua --- @@ -298,7 +297,7 @@ MiniNotify.make_notify = function(opts) if type(val.hl_group) ~= 'string' then H.error('`hl_group` in level data should be string.') end end - return function(msg, level) + return vim.schedule_wrap(function(msg, level) level = level or vim.log.levels.INFO local level_name = level_names[level] if level_name == nil then H.error('Only valid values of `vim.log.levels` are supported.') end @@ -308,7 +307,7 @@ MiniNotify.make_notify = function(opts) local id = MiniNotify.add(msg, level_name, level_data.hl_group) vim.defer_fn(function() MiniNotify.remove(id) end, level_data.duration) - end + end) end --- Add notification diff --git a/tests/test_notify.lua b/tests/test_notify.lua index 4b7872e9..31f39f5b 100644 --- a/tests/test_notify.lua +++ b/tests/test_notify.lua @@ -270,9 +270,23 @@ T['make_notify()']['has output working in fast event'] = function() eq(get_all()[1].msg, 'Hello') end +T['make_notify()']['has output working when completion is active'] = function() + child.lua([[ + vim.notify = MiniNotify.make_notify() + _G.completefunc_notify = function() vim.notify("Hello", vim.log.levels.INFO) end + ]]) + child.o.completefunc = 'v:lua.completefunc_notify' + child.type_keys('i', '') + sleep(small_time + small_time) + eq(child.cmd_capture('messages'), '') + eq(get_all()[1].msg, 'Hello') +end + T['make_notify()']['has output validating arguments'] = function() child.lua('vim.notify = MiniNotify.make_notify()') - expect.error(function() child.lua([[vim.notify('Hello', 'ERROR')]]) end, 'valid values.*vim%.log%.levels') + child.lua([[vim.notify('Hello', 'ERROR')]]) + sleep(small_time) + expect.match(child.cmd_capture('messages'), 'valid values.*vim%.log%.levels') end T['make_notify()']['allows non-positive `duration`'] = function()