aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter
diff options
context:
space:
mode:
authorIgor <igorlfs@ufmg.br>2024-12-29 12:23:24 -0300
committerLewis Russell <me@lewisr.dev>2024-12-29 16:24:19 +0000
commite4bc8b5967d22840c1e52c97acab0f77107cd48c (patch)
tree3966824de4bcae5929acb42b367970a48d623af8 /runtime/lua/vim/treesitter
parent02097e43c8cf33b4302717a489d322ac47fa15c2 (diff)
downloadrneovim-e4bc8b5967d22840c1e52c97acab0f77107cd48c.tar.gz
rneovim-e4bc8b5967d22840c1e52c97acab0f77107cd48c.tar.bz2
rneovim-e4bc8b5967d22840c1e52c97acab0f77107cd48c.zip
fix(treesitter.foldexpr): only refresh valid buffers
Problem: autocmd to refresh folds always uses the current buffer if the option type is local. However, the current buffer may not have a parser, and thus the assert that checks for a parser could fail. Solution: check if the foldinfo contains the buffer, and only refresh if so.
Diffstat (limited to 'runtime/lua/vim/treesitter')
-rw-r--r--runtime/lua/vim/treesitter/_fold.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/_fold.lua b/runtime/lua/vim/treesitter/_fold.lua
index 10ba074ab5..207ac1ab67 100644
--- a/runtime/lua/vim/treesitter/_fold.lua
+++ b/runtime/lua/vim/treesitter/_fold.lua
@@ -378,8 +378,10 @@ api.nvim_create_autocmd('OptionSet', {
pattern = { 'foldminlines', 'foldnestmax' },
desc = 'Refresh treesitter folds',
callback = function()
- local bufs = vim.v.option_type == 'local' and { api.nvim_get_current_buf() }
- or vim.tbl_keys(foldinfos)
+ local buf = api.nvim_get_current_buf()
+ local bufs = vim.v.option_type == 'global' and vim.tbl_keys(foldinfos)
+ or foldinfos[buf] and { buf }
+ or {}
for _, bufnr in ipairs(bufs) do
foldinfos[bufnr] = FoldInfo.new()
api.nvim_buf_call(bufnr, function()