ej-shafran / compile-mode.nvim

A plugin for Neovim inspired by Emacs' Compilation Mode
The Unlicense
50 stars 12 forks source link

Invalid buffer id: -1 #23

Closed vunhatchuong closed 1 month ago

vunhatchuong commented 1 month ago

Describe the bug When I run :Compile every time after the 1st time the error always appears.

To Reproduce Steps to reproduce the behavior:

  1. Open a buffer
  2. Run :Compile
  3. Type zig build
  4. See error

Expected behavior The compile buffer opens and run the command.

Screenshots image

Neovim Version

v0.10.1

compile-mode.nvim Version v4.0.0

Additional context image

ej-shafran commented 1 month ago

Thanks for letting me know! Will fix this soon

ej-shafran commented 1 month ago

Hi @vunhatchuong - I can't seem to reproduce your bug... Do you mind sharing your compile-mode configuration? Or trying to reproduce this with a minimal config?

vunhatchuong commented 1 month ago
{
  "ej-shafran/compile-mode.nvim",
  cmd = { "Compile", "Recompile" },
  dependencies = {
      "nvim-lua/plenary.nvim",
  },
  keys = {
      { "<leader>ox", "<cmd>Compile<cr>", desc = "Compile" },
      {
          "<leader>or",
          function()
              vim.cmd("Recompile")
          end,
          desc = "Compile",
      },
  },
  config = function()
      vim.g.compile_mode = {}
  end,
},

There's some interesting thing here:

vunhatchuong commented 1 month ago

Changing every instance of bufnr to 0 thus reverting this commit "fixes" it.

vunhatchuong commented 1 month ago

The doc of [vim.fn.bufnr](https://neovim.io/doc/user/builtin.html#bufnr()) stated that it will return -1 (like my bug) if the buffer doesn't exist.

Seems like Windows doesn't like buffer name with * suffix.

So these will work:

vim.g.compile_mode = {
    buffer_name = "*compilation",
    -- buffer_name = "compilation",
}

But not:

vim.g.compile_mode = {
    buffer_name = "compilation*",
}
vunhatchuong commented 1 month ago

So remove vim.fn.fnameescape fixes the problem:

ftplugin/compilation.lua:4

- local bufnr = vim.fn.bufnr(vim.fn.fnameescape(config.buffer_name))
+ local bufnr = vim.fn.bufnr(config.buffer_name)
ej-shafran commented 1 month ago

How interesting... I added the fnameescape to try and fix an issue with this exact thing. I'll give this another look and try to push a fix to nightly sometime today.

ej-shafran commented 1 month ago

Alright; finally managed to properly setup Windows in the CI, and the error is happening there. Will try to solve and hopefully the CI can act as a check for all platforms from now on.

ej-shafran commented 1 month ago

Ahh. This seems to summarize it pretty well:

https://github.com/neovim/neovim/issues/3912#issuecomment-167899148

I'll take a look at removing the fnameescape call, then. Maybe it's time to change the default compilation buffer name, as well, since these wildcards seem to only cause issues.

ej-shafran commented 1 month ago

Hiya. I believe the changes in 4.0.1 should fix your issue. Mind giving it a look and seeing that everything seems to be fine?

vunhatchuong commented 1 month ago

Fixed.