Skip to content

Commit

Permalink
feat: add line_length to large buffer detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Feb 7, 2025
1 parent dda036f commit aa76560
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lua/astrocore/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
---@class AstroCoreMaxFile
---@field size integer? the number of bytes in a file
---@field lines integer? the number of lines in a file
---@field line_length integer? the average line length in a file

---@class AstroCoreSessionAutosave
---@field last boolean? whether or not to save the last session
Expand Down Expand Up @@ -308,7 +309,7 @@ local M = {
cmp = true,
diagnostics_mode = 3,
highlighturl = true,
large_buf = { size = 1024 * 256, lines = 10000 },
large_buf = { size = 1024 * 256, lines = 10000, line_length = 1000 },
notifications = true,
},
git_worktrees = nil,
Expand Down
6 changes: 5 additions & 1 deletion lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,12 @@ function M.setup(opts)
callback = function(args)
-- TODO: remove `vim.loop` when dropping support for Neovim v0.9
local ok, stats = pcall((vim.uv or vim.loop).fs_stat, vim.api.nvim_buf_get_name(args.buf))
local file_size = ok and stats and stats.size or 0
local line_count = vim.api.nvim_buf_line_count(args.buf)
if
(ok and stats and stats.size > large_buf.size) or vim.api.nvim_buf_line_count(args.buf) > large_buf.lines
file_size > large_buf.size
or line_count > large_buf.lines
or (file_size / line_count) - 1 > large_buf.line_length
then
vim.b[args.buf].large_buf = true
M.event("LargeBuf", true)
Expand Down

0 comments on commit aa76560

Please sign in to comment.