Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(bigfile): refactor bigfile utils #673

Merged
merged 10 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lua/builtin/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ M.window = {
min = 20,
max = 60,
},
prompt = {
scale = 0.3,
min = 20,
max = 60,
},
},
blend = 15,
}
Expand Down
15 changes: 3 additions & 12 deletions lua/builtin/others.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,9 @@ local builtin_others_augroup =
vim.api.nvim_create_autocmd("BufReadPre", {
group = builtin_others_augroup,
callback = function(event)
local f = vim.fn.expand("<afile>")
if vim.fn.getfsize(f) > constants.perf.maxfilesize then
vim.cmd([[
syntax clear
setlocal eventignore+=FileType
setlocal undolevels=-1
]])
if type(event) == "table" and type(event.buf) == "number" then
vim.treesitter.stop(event.buf)
vim.diagnostic.enable(false, { bufnr = event.buf })
vim.lsp.stop_client(vim.lsp.get_clients({ bufnr = event.buf }))
end
local bigfile = require("builtin.utils.bigfile")
if type(event) == "table" and type(event.buf) == "number" and bigfile.is_too_big(event.buf) then
bigfile.make_file_quick(event.buf)
end
end,
})
Expand Down
33 changes: 33 additions & 0 deletions lua/builtin/utils/bigfile.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local uv = vim.uv or vim.loop

---@param bufnr integer?
---@return boolean
local function is_too_big(bufnr)
if type(bufnr) == "number" then
local constants = require("builtin.constants")
local ok, stats = pcall(uv.fs_stat --[[@as function]], vim.api.nvim_buf_get_name(bufnr))
return ok and stats and stats.size > constants.perf.maxfilesize
end
return false
end

---@param bufnr integer?
local function make_file_quick(bufnr)
if is_too_big(bufnr) then
vim.cmd([[
syntax clear
setlocal eventignore+=FileType
setlocal undolevels=-1
]])
vim.treesitter.stop(bufnr)
vim.diagnostic.enable(false, { bufnr = bufnr })
vim.lsp.stop_client(vim.lsp.get_clients({ bufnr = bufnr }))
end
end

local M = {
is_too_big = is_too_big,
make_file_quick = make_file_quick,
}

return M
9 changes: 3 additions & 6 deletions lua/configs/RRethy/vim-illuminate/config.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
local constants = require("builtin.constants")
local bigfile = require("builtin.utils.bigfile")

require("illuminate").configure({
providers = {
"regex",
},
providers = { "regex" },
-- disable for big file
should_enable = function(bufnr)
local f = vim.api.nvim_buf_get_name(bufnr)
return vim.fn.getfsize(f) <= constants.perf.maxfilesize
return not bigfile.is_too_big(bufnr)
end,
})

Expand Down
8 changes: 0 additions & 8 deletions lua/configs/liuchengxu/vista-vim/init.lua

This file was deleted.

12 changes: 0 additions & 12 deletions lua/configs/liuchengxu/vista-vim/keys.lua

This file was deleted.

5 changes: 2 additions & 3 deletions lua/configs/lukas-reineke/indent-blankline-nvim/config.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
local constants = require("builtin.constants")
local bigfile = require("builtin.utils.bigfile")

require("ibl").setup({
scope = { enabled = false },
})

local hooks = require("ibl.hooks")
hooks.register(hooks.type.ACTIVE, function(bufnr)
local f = vim.api.nvim_buf_get_name(bufnr)
return vim.fn.getfsize(f) <= constants.perf.maxfilesize
return bigfile.is_too_big(bufnr)
end)
135 changes: 0 additions & 135 deletions lua/configs/nvim-telescope/telescope-nvim/config.lua

This file was deleted.

99 changes: 0 additions & 99 deletions lua/configs/nvim-telescope/telescope-nvim/keys.lua

This file was deleted.

6 changes: 2 additions & 4 deletions lua/configs/nvim-treesitter/nvim-treesitter/config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local constants = require("builtin.constants")
local bigfile = require("builtin.utils.bigfile")
local message = require("builtin.utils.message")
local uv = vim.uv or vim.loop

Expand All @@ -23,9 +23,7 @@ require("nvim-treesitter.configs").setup({
enable = true,
-- disable for super large file
disable = function(lang, buf)
local max_filesize = constants.perf.maxfilesize
local ok, stats = pcall(uv.fs_stat, vim.api.nvim_buf_get_name(buf))
return ok and stats and stats.size > max_filesize
return bigfile.is_too_big(buf)
end,
additional_vim_regex_highlighting = false,
},
Expand Down
Loading
Loading