gorbit99/codewindow.nvim

Error: /nvim/lazy/codewindow.nvim/lua/codewindow/highlight.lua:241: Invalid buffer id: 51

nyngwang opened this issue · 5 comments

Error executing vim.schedule lua callback: ...e/nvim/lazy/codewindow.nvim/lua/codewindow/highlight.lua:241: Invalid buffer id: 51
stack traceback:
	[C]: in function 'nvim_buf_clear_namespace'
	...e/nvim/lazy/codewindow.nvim/lua/codewindow/highlight.lua:241: in function 'display_cursor'
	...local/share/nvim/lazy/codewindow.nvim/lua/codewindow.lua:17: in function ''
	vim/_editor.lua: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

It might be that some API calls can be protected by checking whether or not it's valid using nvim_buf_is_valid.

codewindow-issue-61-invalid_buf_id.mov

These are the two autocmds I used in the DEMO: (with the augroup name removed.)

-- if I remove the first one then the error disappear, but then the minimap will not be closed.
vim.api.nvim_create_autocmd({ 'WinLeave', 'TermEnter' }, {
  callback = vim.schedule_wrap(function ()
    require('codewindow').close_minimap()
  end)
})
vim.api.nvim_create_autocmd({ 'CursorHold' }, {
  callback = vim.schedule_wrap(function ()
    if vim.api.nvim_win_get_config(0).relative == 'editor'
      and vim.api.nvim_buf_is_valid(0)
    then
      pcall(require('codewindow').open_minimap)
    end
  end)
})

I'm curious, what are you trying to achieve with these autocommands?

[...], what are you trying to achieve with these autocommands?

Basically active_in_terminals = false + auto_enable = true with a note that the minimap should only be enabled when it on a floating window, but the latter is buggy (it produce a similar error about invalid something, so I decided to do it myself)


TL;DR: I think the two events Term{Enter, Open} should be added when you're closing the minimap given auto_enable = true.

I just resolved it after some trying:

vim.api.nvim_create_autocmd({
  'TermEnter', 'TermOpen', -- for me these two events seem to be the key!
  'BufLeave'
}, {
  group = curfile_augroup,
  callback = function ()
    require('codewindow').close_minimap()
  end
})
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
  group = curfile_augroup,
  callback = vim.schedule_wrap(function ()
    if vim.api.nvim_win_get_config(0).relative == 'editor' then
      require('codewindow').open_minimap()
    end
  end)
})

Try putting in the terminal's filetype into the "exclude_filetypes" table. If you are using floaterm, this would be floaterm, but ymmv. auto_enable iirc works off of that table

It doesn't work, and I think that is unrelated to my problem because the error was triggered when I closed the floating window in my demo. (I did try exclude_filetypes with fzf for fzf-lua, but again it didn't solve it.)

Interesting, anyways, if you could solve the problem, that's great. The project is very much in need of a proper rewrite anyways, I'll see what I can do then.