xvzc / chezmoi.nvim

Chezmoi plugin for neovim
MIT License
73 stars 3 forks source link

Fix possible error E5560 when notifying #1

Closed jbmorice closed 7 months ago

jbmorice commented 7 months ago

Hi ! Hope it is fine to open a PR like this.

I started using chezmoi.nvim with the following config and rcarriga/nvim-notify as a vim.notify backend.

{
  edit = {
    watch = true,
  },
}

But I recently changed my vim.notify backend to j-hui/fidget.nvim and started to experience the following errors when saving a chezmoi managed buffer.

"~/.local/share/chezmoi/dot_config/nvim/lua/jbmorice/plugins/lspconfig.lua" 106L, 3437B written
Error detected while processing BufWritePost Autocommands for "<buffer=13>":
Error executing lua callback: ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:499: 'chezmoi apply --source-path C:
/Users/Jean-Baptiste/.local/share/chezmoi/dot_config/nvim/lua/jbmorice/plugins/lspconfig.lua' was unable to complete in 5000 m
s
stack traceback:
        [C]: in function 'error'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:499: in function 'wait'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:453: in function 'sync'
        ...m-data/lazy/chezmoi.nvim/lua/chezmoi/commands/__base.lua:38: in function 'execute'
        ...m-data/lazy/chezmoi.nvim/lua/chezmoi/commands/__edit.lua:56: in function <...m-data/lazy/chezmoi.nvim/lua/chezmoi/c
ommands/__edit.lua:46>

Error executing luv callback:
...-data/lazy/fidget.nvim/lua/fidget/notification/model.lua:264: E5560: vimL function must not be called in a lua loop callbac
k
stack traceback:
        [C]: in function 'sort'
        ...-data/lazy/fidget.nvim/lua/fidget/notification/model.lua:264: in function 'update'
        ...l/nvim-data/lazy/fidget.nvim/lua/fidget/notification.lua:257: in function 'notify'
        ...Local/nvim-data/lazy/chezmoi.nvim/lua/chezmoi/notify.lua:8: in function 'plain'
        ...Local/nvim-data/lazy/chezmoi.nvim/lua/chezmoi/notify.lua:12: in function 'info'
        ...m-data/lazy/chezmoi.nvim/lua/chezmoi/commands/__edit.lua:62: in function '_user_on_exit'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:240: in function '_shutdown'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:47: in function <...ta/Local/nvim-data/lazy/plenary.nvim/l
ua/plenary/job.lua:38>
        [C]: in function 'wait'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:486: in function 'wait'
        ...ta/Local/nvim-data/lazy/plenary.nvim/lua/plenary/job.lua:453: in function 'sync'
        ...m-data/lazy/chezmoi.nvim/lua/chezmoi/commands/__base.lua:38: in function 'execute'
        ...m-data/lazy/chezmoi.nvim/lua/chezmoi/commands/__edit.lua:56: in function <...m-data/lazy/chezmoi.nvim/lua/chezmoi/c
ommands/__edit.lua:46>

I am not very experienced with lua and neovim development but here is my understanding of the issue:

The solution I found was to guard the vim.notify call in lua/chezmoi/notify.lua by a vim.in_fast_event() check and passing it through a vim.schedule call when it is true.

And thanks four your work on this plugin, it has greatly improved my workflow when editing my neovim config. 😃

xvzc commented 7 months ago

Looks great! Thanks!