[Backport release-0.9] fix(treesitter): allow foldexpr without highlights (#23673)

fix(treesitter): allow foldexpr without highlights (#23672)

Ref nvim-treesitter/nvim-treesitter#4748

Co-authored-by: Lewis Russell <lewis6991@gmail.com>
This commit is contained in:
Christian Clason
2023-05-21 11:36:18 +02:00
committed by GitHub
parent 2be8c29406
commit c8d6d14f71
2 changed files with 2 additions and 12 deletions

View File

@@ -279,7 +279,8 @@ function M.foldexpr(lnum)
lnum = lnum or vim.v.lnum
local bufnr = api.nvim_get_current_buf()
if not vim.treesitter._has_parser(bufnr) or not lnum then
local parser = vim.F.npcall(vim.treesitter.get_parser, bufnr)
if not parser then
return '0'
end
@@ -287,7 +288,6 @@ function M.foldexpr(lnum)
foldinfos[bufnr] = FoldInfo.new()
get_folds_levels(bufnr, foldinfos[bufnr])
local parser = vim.treesitter.get_parser(bufnr)
parser:register_cbs({
on_changedtree = function(tree_changes)
on_changedtree(bufnr, foldinfos[bufnr], tree_changes)