nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
6.02k stars 462 forks source link

Bug: Invalid window ID #1231

Closed refLog2112 closed 4 months ago

refLog2112 commented 5 months ago

Self Checks

How to reproduce the problem

  1. Set buffers in Split View
  2. Open command line

Expected behaviour

No error message is shown

Actual behaviour

Error detected while processing ModeChanged Autocommands for "*":
E5108: Error executing lua .../.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:429: Invalid window id: 1001
stack traceback:
    [C]: in function 'nvim_win_call'
    .../.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:429: in function 
        <.../.local/share/nvim/lazy/lualine.nvim/lua/lualine.lua:318>

Minimal config to reproduce the issue

  1. Noice plugin
  2. globalstatus = true

Additional information

Everything works fine if a single buffer is in focus

liath commented 4 months ago

Added some guards around the failing line and it seems to clear this up:

diff --git a/lua/lualine.lua b/lua/lualine.lua
index 6093049..e75f79e 100644
--- a/lua/lualine.lua
+++ b/lua/lualine.lua
@@ -426,8 +426,13 @@ local function refresh(opts)
           and vim.fn.win_gettype(refresh_real_curwin) == 'popup'
           and refresh_real_curwin
         or win
-      local stl_cur = vim.api.nvim_win_call(refresh_real_curwin, M.statusline)
+
+      local win_is_num = type(refresh_real_curwin) == "number"
+      local win_is_valid = win_is_num and vim.api.nvim_win_is_valid(refresh_real_curwin)
+
+      local stl_cur = win_is_valid and vim.api.nvim_win_call(refresh_real_curwin, M.statusline) or ""
       local stl_last = modules.nvim_opts.get_cache('statusline', { window = set_win })
+
       if stl_cur or stl_last then
         modules.nvim_opts.set('statusline', stl_cur, { window = set_win })
       end

There's probably a better fix that would answer why refresh_real_curwin is ocassionally:

refLog2112 commented 4 months ago

@liath Indeed this fix kind of works, but is hiding the status line. @folke is there something that can be related to Noice?

Regardless of how many splits are there, the Invalid window id: 1001 is always the error cause.

liath commented 4 months ago

I reverted my change to see if I could find a better solution but can't seem to reproduce now. I pulled updates fwiw, maybe it'll help you @refLog2112

folke commented 4 months ago

I dont see this issse. What are the exact steps to reproduce this using Noice and lualine?

refLog2112 commented 4 months ago

@folke Here are the steps with a little demo

  1. Open 2+ buffers and put them in split
  2. Switch between the splits
  3. Open command line in each steps
folke commented 4 months ago

Still can't reproduce. Since both noice and lualine are part of LazyVim which is used by thousands of people, I would also be very surprised there's an interop issue there.

Feel free to open an issue in the noice repo with a minimal repro as instructed in the issue template.

refLog2112 commented 4 months ago

The issue seems to be a job started with plenary. Closing this issue.

AlexvZyl commented 4 months ago

@refLog2112 Running into the same issue. Would you mind sharing what your fix was?

refLog2112 commented 4 months ago

@AlexvZyl I see that you have also a plenary job that does the git compare and put it the lualine. Actually, I just disabled that section for now, and all was fine.

        -- Run job to get git.
        local result = Job:new({
            command = 'git',
            cwd = curr_dir,
            args = { 'rev-list', '--left-right', '--count', 'HEAD...@{upstream}' },
        })
            :sync(100)[1]
            {
                U.get_git_compare,
                separator = ' ',
                padding = 0,
                color = text_hl,
            },

My guess is that plenary creates a window id which no longer exists after the job is done.