luckasRanarison/tailwind-tools.nvim

Invalid buffer id when quitting a window

Closed this issue · 0 comments

Describe the bug
When I quit some windows, tailwind-tools errors, and keeps erroring on BufEnter and TextChanged.

To Reproduce
You'll need to use the vim-fugitive plugin, https://github.com/tpope/vim-fugitive, like I do.
I prepared a repo you can clone: https://github.com/Gnarus-G/tailwind-tools-bug-repo
Steps to reproduce the behavior:

  1. Open src/app/page.tsx
  2. Edit it (doesn't matter how you edit it)
  3. Open fugitive and stage
  4. Open the commit prompt, :G commit
  5. :q quit it
  6. See error

Expected behavior
Doesn't error

Screenshots
image

Environment (please complete the following information):

  • Operating system: Linux rig 6.8.1-zen1-1-zen # 1 ZEN SMP PREEMPT_DYNAMIC Sat, 16 Mar 2024 17:15:23 +0000 x86_64 GNU/Linux
  • Neovim version: NVIM v0.10.0-dev-2657+g9765efb40f
    Build type: RelWithDebInfo
    LuaJIT 2.1.1702233742
  • Nvim-treesitter commit: Latest commit of master
  • tailwind-language-server version: 0.0.16

Additional context
I'm not a lua expert, but I think I know the exact issue. The callback closure in the create_autocmd options closes over bufnr. I don't understand enough to know how you should fix this. But I presume you can use the buf number from a argument.

M.on_attach = function(args)
  local bufnr = args.buf
  local client = get_tailwindcss()

  if not client then return end

  vim.api.nvim_create_autocmd(color_events, {
    group = vim.g.tailwind_tools.color_au,
    callback = function(a)
      if not state.color.enabled then return end
      if a.event == "TextChangedI" then
        debounced_color_request(bufnr)
      elseif vim.startswith(a.event, "Cursor") == state.conceal.enabled then
        M.color_request(bufnr)
      end
    end,
  })

  M.color_request(bufnr)
end