summaryrefslogtreecommitdiff
path: root/lua/lvim/core/treesitter.lua
diff options
context:
space:
mode:
authorLostNeophyte <[email protected]>2022-11-01 10:37:50 +0100
committerGitHub <[email protected]>2022-11-01 10:37:50 +0100
commit978ff7c24de968d5f2f956b72a196773ae80b903 (patch)
treef354951f609d37d6952c906c1439a7aa5175927f /lua/lvim/core/treesitter.lua
parenteabf6c6990cb7ac9416b1733cf59c36c85f50777 (diff)
perf(treesitter): disable in big files (#3268)
* perf(treesitter): disable in big files * fix: disable `use_treesitter` in indentlines and remove vim.schedule * refactor(treesitter): use `vim.schedule` * perf: set nocursorline in big json files * perf: disable more things in big files * chore: format
Diffstat (limited to 'lua/lvim/core/treesitter.lua')
-rw-r--r--lua/lvim/core/treesitter.lua39
1 files changed, 38 insertions, 1 deletions
diff --git a/lua/lvim/core/treesitter.lua b/lua/lvim/core/treesitter.lua
index fcada24f..9b50986e 100644
--- a/lua/lvim/core/treesitter.lua
+++ b/lua/lvim/core/treesitter.lua
@@ -13,7 +13,44 @@ M.config = function()
highlight = {
enable = true, -- false will disable the whole extension
additional_vim_regex_highlighting = false,
- disable = { "latex" },
+ disable = function(lang, buf)
+ if vim.tbl_contains({ "latex" }, lang) then
+ return true
+ end
+
+ local max_filesize = 1024 * 1024
+ local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
+ if ok and stats and stats.size > max_filesize then
+ if lvim.builtin.illuminate.active then
+ pcall(require("illuminate").pause_buf)
+ end
+
+ vim.schedule(function()
+ vim.api.nvim_buf_call(buf, function()
+ vim.cmd "setlocal noswapfile noundofile"
+
+ if vim.tbl_contains({ "json" }, lang) then
+ vim.cmd "NoMatchParen"
+ vim.cmd "syntax off"
+ vim.cmd "syntax clear"
+ vim.cmd "setlocal nocursorline nolist bufhidden=unload"
+
+ vim.api.nvim_create_autocmd({ "BufDelete" }, {
+ callback = function()
+ vim.cmd "DoMatchParen"
+ vim.cmd "syntax on"
+ end,
+ buffer = buf,
+ })
+ end
+ end)
+ end)
+
+ Log:info "File larger than 1MB, turned off treesitter for this buffer"
+
+ return true
+ end
+ end,
},
context_commentstring = {
enable = true,