Skip to content

Commit

Permalink
perf(treesitter): set regions early
Browse files Browse the repository at this point in the history
  • Loading branch information
xzbdmw committed Oct 16, 2024
1 parent 254145f commit aa67660
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lua/trouble/view/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ function M._attach_lang(buf, lang, regions)
M.cache[buf] = M.cache[buf] or {}

if not M.cache[buf][lang] then
local ok, parser = pcall(vim.treesitter.get_parser, buf, lang)
local ok, parser = pcall(vim.treesitter.languagetree.new, buf, lang)
if not ok then
local msg = "nvim-treesitter parser missing `" .. lang .. "`"
vim.notify_once(msg, vim.log.levels.WARN, { title = "trouble.nvim" })
return
end

parser:set_included_regions(vim.deepcopy(regions))
M.cache[buf][lang] = {
parser = parser,
highlighter = TSHighlighter.new(parser),
Expand All @@ -80,7 +81,7 @@ function M._attach_lang(buf, lang, regions)
M.cache[buf][lang].enabled = true
local parser = M.cache[buf][lang].parser

parser:set_included_regions(regions)
parser:set_included_regions(vim.deepcopy(regions))
end

return M

0 comments on commit aa67660

Please sign in to comment.