fix(treesitter): injected lang ranges may cross capture boundaries #32549

Problem:
treesitter injected language ranges sometimes cross over the capture
boundaries when `@combined`.

Solution:
Clip child regions to not spill out of parent regions within
languagetree.lua, and only apply highlights within those regions in
highlighter.lua.


Co-authored-by: Cormac Relf <web@cormacrelf.net>
This commit is contained in:
Riley Bruins
2025-04-13 14:22:17 -07:00
committed by GitHub
parent ee3f9a1e03
commit 0977f70f4d
4 changed files with 213 additions and 42 deletions

View File

@@ -114,6 +114,19 @@ function M.intercepts(r1, r2)
return true
end
---@private
---@param r1 Range6
---@param r2 Range6
---@return Range6?
function M.intersection(r1, r2)
if not M.intercepts(r1, r2) then
return nil
end
local rs = M.cmp_pos.le(r1[1], r1[2], r2[1], r2[2]) and r2 or r1
local re = M.cmp_pos.ge(r1[4], r1[5], r2[4], r2[5]) and r2 or r1
return { rs[1], rs[2], rs[3], re[4], re[5], re[6] }
end
---@private
---@param r Range
---@return integer, integer, integer, integer