aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/_range.lua
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2025-04-13 14:22:17 -0700
committerGitHub <noreply@github.com>2025-04-13 14:22:17 -0700
commit0977f70f4dd3d14175697d5e6568d4019019506f (patch)
treec93eed86602cae75fbc84e1c30326a1af38b84b8 /runtime/lua/vim/treesitter/_range.lua
parentee3f9a1e03a93ab2a75a6f7a2f3bb2f4c6b4e736 (diff)
downloadrneovim-0977f70f4dd3d14175697d5e6568d4019019506f.tar.gz
rneovim-0977f70f4dd3d14175697d5e6568d4019019506f.tar.bz2
rneovim-0977f70f4dd3d14175697d5e6568d4019019506f.zip
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>
Diffstat (limited to 'runtime/lua/vim/treesitter/_range.lua')
-rw-r--r--runtime/lua/vim/treesitter/_range.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter/_range.lua b/runtime/lua/vim/treesitter/_range.lua
index 82ab8517aa..b1595cf8f6 100644
--- a/runtime/lua/vim/treesitter/_range.lua
+++ b/runtime/lua/vim/treesitter/_range.lua
@@ -115,6 +115,19 @@ function M.intercepts(r1, r2)
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
function M.unpack4(r)