Skip to content

Commit 0323aa1

Browse files
committed
perf(folding): cache treesitter parser checking
1 parent d8e8b4e commit 0323aa1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lua/astroui/folding.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ local config = require("astroui").config.folding
1212

1313
local is_setup = false
1414
local lsp_bufs = {}
15+
local ts_bufs = {}
1516

1617
local fold_methods = {
1718
lsp = function(lnum, bufnr)
1819
if lsp_bufs[bufnr or vim.api.nvim_get_current_buf()] then return vim.lsp.foldexpr(lnum) end
1920
end,
2021
treesitter = function(lnum, bufnr)
21-
if vim.bo.filetype and pcall(vim.treesitter.get_parser, bufnr) then return vim.treesitter.foldexpr(lnum) end
22+
if ts_bufs[bufnr] == nil then
23+
ts_bufs[bufnr] = vim.bo.filetype and pcall(vim.treesitter.get_parser, bufnr) or false
24+
end
25+
if ts_bufs[bufnr] then return vim.treesitter.foldexpr(lnum) end
2226
end,
2327
indent = function(lnum, bufnr)
2428
if not lnum then lnum = vim.v.lnum end

0 commit comments

Comments
 (0)