feat(bigfile): configurable average line length (default = 1000). Useful for minified files. Closes #576. Closes #372

This commit is contained in:
Folke Lemaitre 2025-02-06 15:08:26 +01:00
parent 1a30610ab7
commit 7fa92a2450
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -12,6 +12,7 @@ M.meta = {
local defaults = { local defaults = {
notify = true, -- show notification when big file detected notify = true, -- show notification when big file detected
size = 1.5 * 1024 * 1024, -- 1.5MB size = 1.5 * 1024 * 1024, -- 1.5MB
line_length = 1000, -- average line length (useful for minified files)
-- Enable or disable features when big file detected -- Enable or disable features when big file detected
---@param ctx {buf: number, ft:string} ---@param ctx {buf: number, ft:string}
setup = function(ctx) setup = function(ctx)
@ -36,12 +37,15 @@ function M.setup()
pattern = { pattern = {
[".*"] = { [".*"] = {
function(path, buf) function(path, buf)
return vim.bo[buf] if not path or not buf or vim.bo[buf].filetype == "bigfile" then
and vim.bo[buf].filetype ~= "bigfile" return
and path end
and vim.fn.getfsize(path) > opts.size local size = vim.fn.getfsize(path)
and "bigfile" if size > opts.size then
or nil return "bigfile"
end
local lines = vim.api.nvim_buf_line_count(buf)
return (size - lines) / lines > opts.line_length and "bigfile" or nil
end, end,
}, },
}, },