Skip to content

Commit 0143bb5

Browse files
logger: schedule vim.notify (#237)
Co-authored-by: Zephyr Lykos <[email protected]>
1 parent 1347f22 commit 0143bb5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lua/null-ls/logger.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,18 @@ end
8080
---@param msg any
8181
function log:warn(msg)
8282
self:add_entry(msg, "warn")
83-
vim.notify(self.__notify_fmt(msg), vim.log.levels.WARN, default_notify_opts)
83+
vim.schedule(function()
84+
vim.notify(self.__notify_fmt(msg), vim.log.levels.WARN, default_notify_opts)
85+
end)
8486
end
8587

8688
---Add a log entry at ERROR level
8789
---@param msg any
8890
function log:error(msg)
8991
self:add_entry(msg, "error")
90-
vim.notify(self.__notify_fmt(msg), vim.log.levels.ERROR, default_notify_opts)
92+
vim.schedule(function()
93+
vim.notify(self.__notify_fmt(msg), vim.log.levels.ERROR, default_notify_opts)
94+
end)
9195
end
9296

9397
setmetatable({}, log)

test/spec/builtins/diagnostics/regal_spec.lua

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ stub(vim, "notify")
77
describe("diagnostics regal", function()
88
local parser = diagnostics.regal._opts.on_output
99

10+
local wait_for_scheduler = function()
11+
vim.wait(0)
12+
end
13+
1014
it("should create a diagnostic with error severity", function()
1115
local output = vim.json.decode([[
1216
{
@@ -62,6 +66,7 @@ describe("diagnostics regal", function()
6266
it("should log error for non-json output", function()
6367
local diagnostic = parser({ output = "non-json-output", err = "json error" })
6468
assert.same({}, diagnostic)
69+
wait_for_scheduler()
6570
assert
6671
.stub(vim.notify)
6772
.was_called_with("[null-ls] non-json-output", vim.log.levels.ERROR, { title = "null-ls" })

0 commit comments

Comments
 (0)