rebelot / heirline.nvim

Heirline.nvim is a no-nonsense Neovim Statusline plugin designed around recursive inheritance to be exceptionally fast and versatile.
MIT License
966 stars 38 forks source link

Error on exit if multiple components uses `vim.schedule_wrap` #203

Open likalium opened 3 days ago

likalium commented 3 days ago

Hello, I have three statusline components that, when updating, execute vim.schedule_wrap(function() ... end) as callback:

local viMode = {
  update = {
    "ModeChanged",
    pattern = "*:*",
    callback = vim.schedule_wrap(function()
      vim.cmd("redrawstatus")
    end),
  }
}
local git = {
  update = {
    "User",
    pattern = "GitSignsUpdate",
    callback = vim.schedule_wrap(function()
      vim.cmd("redrawstatus")
    end),
  }
}
local diagnostics = {
  update = {
    "DiagnosticChanged",
    callback = vim.schedule_wrap(function()
      vim.cmd("redrawstatus")
      vim.cmd("redrawtabline")
    end),
  }
}

The functions for the git and diagnostics component is to fix the fact that they are updated only on cursor move (see #182). In fact my update = {...} on these components is just an adaptation of the autocommands given in #182.

My problem is that, if more than one of these statusline components are loaded, then on exiting neovim spits an error (see below). But if only one of these is loaded, then no error is given on exit. Also, every component is working perfectly, even if it shows an error on exit. It's just annoying, because the error make neovim to delay when quitting, and also it's still concerning to have an error but you don't really know why. Also, #175 is maybe related. I just wanted to conclude that, thank you VERY much for developing heirline.nvim. I find it an awesome plugin, and I'm really glad you're maintaining it!

The error message:

Error executing vim.schedule lua callback: vim/_editor.lua:0: nvim_exec2(): Vim(redrawstatus):E5108: Error executing lua ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:381: bad argument #1 to 'provider' (string expected, got nil)
stack traceback:
    [C]: in function 'provider'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:381: in function '_eval'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:398: in function '_eval'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:398: in function '_eval'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:398: in function '_eval'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:398: in function '_eval'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:398: in function '_eval'
    ...hare/nvim/lazy/heirline.nvim/lua/heirline/statusline.lua:473: in function 'eval'
    ...ocal/share/nvim/lazy/heirline.nvim/lua/heirline/init.lua:114: in function <...ocal/share/nvim/lazy/heirline.nvim/lua/heirline/init.lua:109>
    [C]: in function 'nvim_exec2'
    vim/_editor.lua: in function 'cmd'
    /home/sodium/.config/nvim/lua/plugins/bars-and-lines.lua:153: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
    [C]: in function 'nvim_exec2'
    vim/_editor.lua: in function 'cmd'
    /home/sodium/.config/nvim/lua/plugins/bars-and-lines.lua:153: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>

NB: "sodium" is my username

rebelot commented 3 days ago

This is related to #175 and I can reproduce only if I sufficiently shrink the window.

While I try to figure out how to properly handle this, here is a workaround:

:au VimLeavePre * set stl=

interestingly this does not work on VimLeavePre, but it does if done manually

:au VimLeavePre * au! Heirline_update_autocmds