fix(scope): make sure to parse the ts tree. Fixes #521

This commit is contained in:
Folke Lemaitre 2025-01-16 08:37:14 +01:00
parent 9499b944e7
commit 4c55f1c2da
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 7 additions and 2 deletions

View file

@ -400,6 +400,7 @@ function TSScope:find(opts)
if not has_parser or parser == nil then
return
end
parser:parse()
local line = vim.fn.nextnonblank(opts.pos[1])
line = line == 0 and vim.fn.prevnonblank(opts.pos[1]) or line
@ -763,4 +764,7 @@ function M.setup()
end
end
M.TSScope = TSScope
M.IdentScope = IndentScope
return M

View file

@ -9,9 +9,10 @@ function M.set_lines(lines, opts)
lines = type(lines) == "string" and vim.split(lines, "\n") or lines
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines --[[ @as string[] ]])
vim.bo.filetype = opts.ft or ""
vim.treesitter.stop()
assert(not vim.b.ts_highlight, "treesitter highlight is still enabled")
vim.b.snacks_ts = nil
if opts.ts then
vim.treesitter.stop()
assert(not vim.b.ts_highlight, "treesitter highlight is still enabled")
vim.treesitter.start()
assert(vim.b.ts_highlight, "treesitter highlight is not enabled")
end