diff --git a/lua/doom/modules/core/treesitter/init.lua b/lua/doom/modules/core/treesitter/init.lua index bbd454d16..595b68688 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 be7906bbc..bdb0137e4 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 c649e9125..1fcbca04a 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 000000000..70ab3a539 --- /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/lua/doom/modules/features/lsp/init.lua b/lua/doom/modules/features/lsp/init.lua index e2a277716..c16dbabc7 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 ea636112f..ef35424ca 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 = { diff --git a/modules.lua b/modules.lua index 04463a58c..1c2ef8db4 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