فهرست منبع

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
LostNeophyte 2 سال پیش
والد
کامیت
978ff7c24d
4فایلهای تغییر یافته به همراه41 افزوده شده و 7 حذف شده
  1. 1 3
      lua/lvim/config/init.lua
  2. 2 2
      lua/lvim/core/indentlines.lua
  3. 0 1
      lua/lvim/core/nvimtree.lua
  4. 38 1
      lua/lvim/core/treesitter.lua

+ 1 - 3
lua/lvim/config/init.lua

@@ -49,7 +49,7 @@ function M:init()
 
   ---@deprecated
   lvim.builtin.notify = {
-    active = false
+    active = false,
   }
 end
 
@@ -98,13 +98,11 @@ local function handle_deprecated_settings()
     deprecation_notice("lvim.builtin.dashboard", "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
   end
 
-
   -- notify.nvim
   if lvim.builtin.notify.active then
     deprecation_notice("lvim.builtin.notify", "See LunarVim#3294")
   end
 
-
   if lvim.autocommands.custom_groups then
     deprecation_notice(
       "lvim.autocommands.custom_groups",

+ 2 - 2
lua/lvim/core/indentlines.lua

@@ -20,8 +20,8 @@ M.config = function()
       char = lvim.icons.ui.LineLeft,
       show_trailing_blankline_indent = false,
       show_first_indent_level = true,
-      use_treesitter = true,
-      show_current_context = true,
+      use_treesitter = false,
+      show_current_context = false,
     },
   }
 end

+ 0 - 1
lua/lvim/core/nvimtree.lua

@@ -147,7 +147,6 @@ function M.setup()
     return
   end
 
-
   if lvim.builtin.nvimtree._setup_called then
     Log:debug "ignoring repeated setup call for nvim-tree, see kyazdani42/nvim-tree.lua#1308"
     return

+ 38 - 1
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,