From 201624c51a1dbec48c490380a3a379ba8ccf53f1 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Wed, 20 Nov 2024 12:07:09 -0600 Subject: [PATCH] perf(nvim): improve startup speed of neovim when treesitter fold missing --- users/price/dots/.config/nvim/lua/core/options.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/users/price/dots/.config/nvim/lua/core/options.lua b/users/price/dots/.config/nvim/lua/core/options.lua index 0e228abb..52df31cb 100755 --- a/users/price/dots/.config/nvim/lua/core/options.lua +++ b/users/price/dots/.config/nvim/lua/core/options.lua @@ -71,15 +71,20 @@ M.setup = function() opt.undofile = true -- Better folding - opt.foldexpr = "v:lua.vim.treesitter.foldexpr()" - opt.foldmethod = "expr" + vim.api.nvim_create_autocmd("FileType", { + callback = function() + if not (pcall(vim.treesitter.start)) then + return + end + vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()" + vim.opt_local.foldmethod = "expr" + end, + }) opt.fillchars = { eob = " ", fold = " ", foldopen = "", foldsep = " ", foldclose = "" } vim.o.foldcolumn = "1" vim.o.foldlevel = 99 vim.o.foldlevelstart = 99 vim.o.foldenable = true - vim.wo.foldexpr = "nvim_treesitter#foldexpr()" - vim.wo.foldmethod = "expr" -- Concealment for nicer rendering opt.conceallevel = 2