fix(treesitter): highlight injections properly

`on_line_impl` doesn't highlight single lines, so using pattern indexes
to offset priority doesn't work.
This commit is contained in:
Lewis Russell
2024-03-13 14:40:41 +00:00
committed by Lewis Russell
parent 274e414c94
commit 12faaf40f4
3 changed files with 56 additions and 20 deletions

View File

@@ -867,6 +867,40 @@ describe('treesitter highlighting (help)', function()
]],
}
end)
it('correctly redraws injections subpriorities', function()
-- The top level string node will be highlighted first
-- with an extmark spanning multiple lines.
-- When the next line is drawn, which includes an injection,
-- make sure the highlight appears above the base tree highlight
insert([=[
local s = [[
local also = lua
]]
]=])
exec_lua [[
parser = vim.treesitter.get_parser(0, "lua", {
injections = {
lua = '(string content: (_) @injection.content (#set! injection.language lua))'
}
})
vim.treesitter.highlighter.new(parser)
]]
screen:expect {
grid = [=[
{3:local} {4:s} {3:=} {5:[[} |
{5: }{3:local}{5: }{4:also}{5: }{3:=}{5: }{4:lua} |
{5:]]} |
^ |
{2:~ }|
|
]=],
}
end)
end)
describe('treesitter highlighting (nested injections)', function()