From 85ef34739df5eed6b5d08cedfdfbf47d6c028e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sat, 31 Dec 2022 16:08:28 +0000 Subject: [PATCH 1/2] fix(luacheck): fix luacheck warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Checking lua/doom/modules/features/lsp/init.lua 1 warning lua/doom/modules/features/lsp/init.lua:214:9: unused variable source_map Checking lua/doom/modules/langs/cc/init.lua 1 warning lua/doom/modules/langs/cc/init.lua:1:7: unused variable utils Signed-off-by: Edwin Török --- lua/doom/modules/features/lsp/init.lua | 8 -------- lua/doom/modules/langs/cc/init.lua | 2 -- 2 files changed, 10 deletions(-) diff --git a/lua/doom/modules/features/lsp/init.lua b/lua/doom/modules/features/lsp/init.lua index e2a27771..c16dbabc 100644 --- a/lua/doom/modules/features/lsp/init.lua +++ b/lua/doom/modules/features/lsp/init.lua @@ -211,14 +211,6 @@ lsp.configs["nvim-cmp"] = function() local replace_termcodes = utils.replace_termcodes - local source_map = { - nvim_lsp = "[LSP]", - luasnip = "[Snp]", - buffer = "[Buf]", - nvim_lua = "[Lua]", - path = "[Path]", - } - --- Helper function to check what behaviour to use --- @return boolean local function check_backspace() diff --git a/lua/doom/modules/langs/cc/init.lua b/lua/doom/modules/langs/cc/init.lua index ea636112..ef35424c 100644 --- a/lua/doom/modules/langs/cc/init.lua +++ b/lua/doom/modules/langs/cc/init.lua @@ -1,5 +1,3 @@ -local utils = require("doom.utils") - local cc = {} cc.settings = { From c271cf09113262b09ad9d7286564bfefd97ce53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Wed, 10 Aug 2022 23:15:23 +0100 Subject: [PATCH 2/2] feat(largefile): disable slow features on large files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use LargeFile.vim to disable syntax highlighting on large files. Gitsigns and treesitter cna also be very slow on large files (e.g. gigabytes of logfiles), so disable these as well. By default a file is considered "large" if it either exceeds 10000 lines, or 1MiB. The linecount is not known when first opening the buffer, hence the need for a file size limit too. Signed-off-by: Edwin Török --- lua/doom/modules/core/treesitter/init.lua | 16 ++++--- lua/doom/modules/features/gitsigns/init.lua | 7 ++- lua/doom/modules/features/illuminate/init.lua | 7 +++ lua/doom/modules/features/largefile/init.lua | 48 +++++++++++++++++++ modules.lua | 1 + 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 lua/doom/modules/features/largefile/init.lua diff --git a/lua/doom/modules/core/treesitter/init.lua b/lua/doom/modules/core/treesitter/init.lua index bbd454d1..595b6868 100644 --- a/lua/doom/modules/core/treesitter/init.lua +++ b/lua/doom/modules/core/treesitter/init.lua @@ -68,13 +68,15 @@ treesitter.packages = { treesitter.configs = {} treesitter.configs["nvim-treesitter"] = function() local is_module_enabled = require("doom.utils").is_module_enabled - require("nvim-treesitter.configs").setup( - vim.tbl_deep_extend("force", doom.core.treesitter.settings.treesitter, { - autopairs = { - enable = is_module_enabled("features", "autopairs"), - }, - }) - ) + local settings = vim.tbl_deep_extend("force", doom.core.treesitter.settings.treesitter, { + autopairs = { + enable = is_module_enabled("features", "autopairs"), + }, + }) + if is_module_enabled("features", "largefile") then + settings = require("doom.modules.features.largefile").update_treesitter(settings) + end + require("nvim-treesitter.configs").setup(settings) -- Check if user is using clang and notify that it has poor compatibility with treesitter -- WARN: 19/11/2021 | issues: #222, #246 clang compatibility could improve in future diff --git a/lua/doom/modules/features/gitsigns/init.lua b/lua/doom/modules/features/gitsigns/init.lua index be7906bb..bdb0137e 100644 --- a/lua/doom/modules/features/gitsigns/init.lua +++ b/lua/doom/modules/features/gitsigns/init.lua @@ -81,7 +81,12 @@ gitsigns.packages = { gitsigns.configs = {} gitsigns.configs["gitsigns.nvim"] = function() - require("gitsigns").setup(doom.features.gitsigns.settings) + local settings = doom.features.gitsigns.settings + local is_module_enabled = require("doom.utils").is_module_enabled + if is_module_enabled("features", "largefile") then + settings.max_file_length = doom.features.largefile.settings.max_line_count + end + require("gitsigns").setup(settings) end return gitsigns diff --git a/lua/doom/modules/features/illuminate/init.lua b/lua/doom/modules/features/illuminate/init.lua index c649e912..1fcbca04 100644 --- a/lua/doom/modules/features/illuminate/init.lua +++ b/lua/doom/modules/features/illuminate/init.lua @@ -20,9 +20,16 @@ illuminate.packages = { }, } + illuminate.configs = {} illuminate.configs["vim-illuminate"] = function() + local is_module_enabled = require("doom.utils").is_module_enabled vim.g.Illuminate_ftblacklist = doom.features.illuminate.settings.blacklist + if is_module_enabled("features", "largefile") then + require('illuminate').configure({ + large_file_cutoff = doom.features.largefile.settings.max_line_count + }) + end end return illuminate diff --git a/lua/doom/modules/features/largefile/init.lua b/lua/doom/modules/features/largefile/init.lua new file mode 100644 index 00000000..70ab3a53 --- /dev/null +++ b/lua/doom/modules/features/largefile/init.lua @@ -0,0 +1,48 @@ +local largefile = {} + +largefile.settings = { + max_line_count = 10000, +} + +largefile.packages = { + ["LargeFile"] = { + "vim-scripts/LargeFile", + commit = "3941a37b2b0288524300348a39521a46539bf9f6", + setup = function() + vim.g.LargeFile = 1 -- 1 MiB + end, + }, +} + +largefile.should_disable = function(_lang, bufnr) + -- need to check file size too: + -- on initial open the buffer would be unloaded and report line count as 0 + -- and we'd trigger an initial parsing of the large file which could be + -- a delay of seconds + local fname = vim.api.nvim_buf_get_name(bufnr) + if string.len(fname) > 0 then + local fsize = vim.fn.getfsize(fname) + if fsize > vim.g.LargeFile * 1024 * 1024 then + -- flag for debugging + vim.b.LargeFile_treesitter_mode_fsize = true + return true + end + end + if vim.api.nvim_buf_line_count(bufnr) > doom.features.largefile.settings.max_line_count then + -- flag for debugging + vim.b.LargeFile_treesitter_mode_linecount = true + return true + end + return false +end + +largefile.update_treesitter = function(settings) + for _, feature in pairs(settings) do + -- keep enable as is, but add a function that runs on buffer open + -- to determine whether to disable the feature for that buffer + feature.disable = largefile.should_disable + end + return settings +end + +return largefile diff --git a/modules.lua b/modules.lua index 04463a58..1c2ef8db 100644 --- a/modules.lua +++ b/modules.lua @@ -26,6 +26,7 @@ return { "indentlines", -- Show indent lines with special characters "range_highlight", -- Highlight selected range from commands "todo_comments", -- Highlight TODO: comments + "largefile", -- Disable treesitter and various other slow features on large files -- "doom_themes", -- Extra themes for doom -- UI Components