summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2025-05-10 10:07:43 -0700
committerLewis Russell <me@lewisr.dev>2025-05-11 08:04:57 +0100
commitde45b8e2754f595eb675bd8068b4f9fc7af8d268 (patch)
tree67915dd8dd250d086214b55edbd9238ea3dda1d6 /runtime/lua/vim
parentbee45fc0e7801396951cd156c82953cbadc256b9 (diff)
fix(treesitter): proper tree `contains()` logic with combined injections
**Problem:** `LanguageTree:contains()` considers any range within the start of the first tree and end of the last tree as "within" the language tree. In the case of combined injections, this is problematic because we only want to consider ranges within any of the combined trees as "contained" (as opposed to any range within the entire range spanned by all combined trees). **Solution:** Use a more discriminative check in `LanguageTree:contains()`.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua13
1 files changed, 7 insertions, 6 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 04e9710bdb..d5deb7452d 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -1287,12 +1287,13 @@ end
local function tree_contains(tree, range)
local tree_ranges = tree:included_ranges(false)
- return Range.contains({
- tree_ranges[1][1],
- tree_ranges[1][2],
- tree_ranges[#tree_ranges][3],
- tree_ranges[#tree_ranges][4],
- }, range)
+ for _, tree_range in ipairs(tree_ranges) do
+ if Range.contains(tree_range, range) then
+ return true
+ end
+ end
+
+ return false
end
--- Determines whether {range} is contained in the |LanguageTree|.