Skip to content

Commit

Permalink
perf: make noice a bit more robust when exiting to prevent possible d…
Browse files Browse the repository at this point in the history
…elays on exit
  • Loading branch information
folke committed Jan 17, 2023
1 parent 3353a7a commit 35e3664
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/noice/message/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function M.get_views()
end

function M.update()
if vim.v.exiting ~= vim.NIL then
if Util.is_exiting() then
return
end

Expand Down
4 changes: 4 additions & 0 deletions lua/noice/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function M.enable()

---@diagnostic disable-next-line: redundant-parameter
vim.ui_attach(Config.ns, options, function(event, kind, ...)
if Util.is_exiting() then
return true
end

local handler = M.get_handler(event, kind, ...)

if not handler then
Expand Down
4 changes: 2 additions & 2 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ end

function M.show_cursor()
if M._guicursor then
if vim.v.exiting == vim.NIL then
if not Util.is_exiting() then
vim.schedule(function()
if M._guicursor and vim.v.exiting == vim.NIL then
if M._guicursor and not Util.is_exiting() then
-- we need to reset all first and then wait for some time before resetting the guicursor. See #114
vim.go.guicursor = "a:"
vim.cmd.redrawstatus()
Expand Down
7 changes: 7 additions & 0 deletions lua/noice/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ function M.interval(ms, fn, opts)
local T = {}

function T.keep()
if M.is_exiting() then
return false
end
return opts.enabled == nil or opts.enabled()
end

Expand Down Expand Up @@ -302,6 +305,10 @@ function M.read_file(file)
return data
end

function M.is_exiting()
return vim.v.exiting ~= vim.NIL
end

function M.write_file(file, data)
local fd = io.open(file, "w+")
if not fd then
Expand Down

0 comments on commit 35e3664

Please sign in to comment.