perf(image): async treesitter parsing for images

This commit is contained in:
Folke Lemaitre 2025-03-01 17:33:45 +01:00
parent 453333530b
commit e55ae37beb
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -84,9 +84,6 @@ M.transforms = {
end,
}
---@diagnostic disable-next-line: invisible
M.TS_ASYNC = (vim.treesitter.languagetree or {})._async_parse ~= nil
local hover ---@type snacks.image.Hover?
local uv = vim.uv or vim.loop
local dir_cache = {} ---@type table<string, boolean>
@ -221,7 +218,7 @@ function M.find(buf, cb, opts)
end
opts = opts or {}
local from, to = opts.from, opts.to
parser:parse(from and to and { from, to } or true)
Snacks.util.parse(parser, from and to and { from, to } or true, function()
local ret = {} ---@type snacks.image.match[]
parser:for_each_tree(function(tstree, tree)
if not tstree then
@ -253,6 +250,7 @@ function M.find(buf, cb, opts)
end
end)
cb(ret)
end)
end
---@param ctx snacks.image.ctx