ソースを参照

perf: handle big files better (#3449)

fixes https://github.com/LunarVim/LunarVim/issues/3393
LostNeophyte 2 年 前
コミット
fb7da7bc78

+ 5 - 0
lua/lvim/config/init.lua

@@ -35,6 +35,11 @@ function M:init()
     },
   }
 
+  lvim.builtin.bigfile = {
+    active = true,
+    config = {},
+  }
+
   require("lvim.config._deprecated").handle()
 end
 

+ 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 = false,
-      show_current_context = false,
+      use_treesitter = true,
+      show_current_context = true,
     },
   }
 end

+ 2 - 32
lua/lvim/core/treesitter.lua

@@ -34,38 +34,8 @@ function M.config()
           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
+        local status_ok, big_file_detected = pcall(vim.api.nvim_buf_get_var, buf, "bigfile_disable_treesitter")
+        return status_ok and big_file_detected
       end,
     },
     context_commentstring = {

+ 10 - 0
lua/lvim/plugins.lua

@@ -281,6 +281,16 @@ local core_plugins = {
     end,
     disable = lvim.colorscheme ~= "onedarker",
   },
+
+  {
+    "lunarvim/bigfile.nvim",
+    config = function()
+      pcall(function()
+        require("bigfile").config(lvim.builtin.bigfile.config)
+      end)
+    end,
+    disable = not lvim.builtin.bigfile.active,
+  },
 }
 
 local default_snapshot_path = join_paths(get_lvim_base_dir(), "snapshots", "default.json")

+ 3 - 0
snapshots/default.json

@@ -8,6 +8,9 @@
   "alpha-nvim": {
     "commit": "a858e4e"
   },
+  "bigfile.nvim": {
+    "commit": "70e4989"
+  },
   "bufferline.nvim": {
     "commit": "4ecfa81"
   },