Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

doom: disable slow features on large files #416

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lua/doom/modules/core/treesitter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lua/doom/modules/features/gitsigns/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions lua/doom/modules/features/illuminate/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 48 additions & 0 deletions lua/doom/modules/features/largefile/init.lua
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions lua/doom/modules/features/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Tab> behaviour to use
--- @return boolean
local function check_backspace()
Expand Down
2 changes: 0 additions & 2 deletions lua/doom/modules/langs/cc/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local utils = require("doom.utils")

local cc = {}

cc.settings = {
Expand Down
1 change: 1 addition & 0 deletions modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down