Skip to content

Commit

Permalink
feat: allow large_buf to be set to false to disable detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Feb 7, 2024
1 parent 2153eaf commit ac0f0bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lua/astrocore/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
---@field cmp boolean? enable or disable cmp on start (boolean; default = true)
---@field highlighturl boolean? enable or disable highlighting of urls on start (boolean; default = true)
---table for defining the size of the max file for all features, above these limits we disable features like treesitter.
---value can also be `false` to disable large buffer detection.
---Example:
---
---```lua
Expand All @@ -85,7 +86,7 @@
--- lines = 10000
---},
---```
---@field large_buf AstroCoreMaxFile?
---@field large_buf AstroCoreMaxFile|false?
---@field notifications boolean? enable or disable notifications on start (boolean; default = true)

---@class AstroCoreOpts
Expand Down
17 changes: 17 additions & 0 deletions lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,23 @@ function M.setup(opts)
end
end

local large_buf = M.config.features.large_buf
if large_buf then
vim.api.nvim_create_autocmd("BufRead", {
group = vim.api.nvim_create_augroup("large_buf_detector", { clear = true }),
desc = "Root detection when entering a buffer",
callback = function(args)
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(args.buf))
if
(ok and stats and stats.size > large_buf.size) or vim.api.nvim_buf_line_count(args.buf) > large_buf.lines
then
vim.b[args.buf].large_buf = true
M.event("LargeBuf", true)
end
end,
})
end

-- initialize rooter
if M.config.rooter then
local root_config = M.config.rooter --[[@as AstroCoreRooterOpts]]
Expand Down

0 comments on commit ac0f0bd

Please sign in to comment.