mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
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()`.
(cherry picked from commit de45b8e275
)
This commit is contained in:
committed by
github-actions[bot]
parent
9965cfb84c
commit
034d3c8f6c
@ -1268,12 +1268,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|.
|
||||
|
Reference in New Issue
Block a user