snacks.nvim
snacks.nvim copied to clipboard
bug(bigfile): doesn't work for filetypes matched by filename
Did you check docs and existing issues?
- [x] I have read all the snacks.nvim docs
- [x] I have updated the plugin to the latest version before submitting this issue
- [x] I have searched the existing issues of snacks.nvim
- [x] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
NVIM v0.11.0-dev-1698+gaa976f0d93
Operating system/version
Linux 6.13.1-arch1-1
Describe the bug
bigfile doesn't enable if a filetype is set via filename
rather than by pattern
. I believe this is because (looking at the documentation for vim.filetype.add()) that if NeoVim enables a filetype by matching on a filename, it never gets to evaluate patterns
, which is how snacks.bigfile works: https://github.com/folke/snacks.nvim/blob/a386e4270b7c083cb95028bcaa1b062b57537817b/lua/snacks/bigfile.lua#L37.
As the example in this bug, this applies to files called COMMIT_EDITMSG
, but I think it applies to any file where the filetype is set based on the filename.
I don't have a suggested fix at this point - putting this in my lazy config for snacks does work for this specific filetype, but that's obviously not a scaleable solution:
config = function()
require("snacks").setup({
bigfile = { notify = true, enabled = true },
})
vim.filetype.add({
filename = {
COMMIT_EDITMSG = {
function(path, buf)
return vim.bo[buf]
and vim.bo[buf].filetype ~= "bigfile"
and path
and vim.fn.getfsize(path) > 1.5 * 1024 * 1024
and "bigfile"
or nil
end,
},
},
})
end,
Steps To Reproduce
- Create a large file called
COMMIT_EDITMSG
, over 1.5MiB in size. - Run
nvim -u repro.lua COMMIT_EDITMSG
. - Type
:set filetype?
and observegitcommit
- Exit Neovim, copy
COMMIT_EDITMSG
toscript.py
(so it's a file not matched using filename, it doesn't matter that it's not really Python code) - Run
nvim -u repro.lua COMMIT_EDITMSG
- Type
set filetype?
and now observebigfile
Expected Behavior
In step (3) above, filetype would be bigfile
.
Repro
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system( "curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro({
spec = {
{ "folke/snacks.nvim", opts = { bigfile = { enabled = true } } },
},
})