fix(treesitter): fix :InspectTree incorrect injections

(cherry picked from commit 284b0e4fa2)
This commit is contained in:
yuukibarns
2025-03-30 23:06:16 +08:00
committed by github-actions[bot]
parent 4422b9bbd0
commit e342b9a25a

View File

@ -1,5 +1,7 @@
local api = vim.api
local Range = require('vim.treesitter._range')
local M = {}
---@class (private) vim.treesitter.dev.TSTreeView
@ -96,9 +98,12 @@ function TSTreeView:new(bufnr, lang)
parser:for_each_tree(function(parent_tree, parent_ltree)
local parent = parent_tree:root()
local parent_range = { parent:range() }
for _, child in pairs(parent_ltree:children()) do
for _, tree in pairs(child:trees()) do
local r = tree:root()
local r_range = { r:range() }
if Range.contains(parent_range, r_range) then
local node = assert(parent:named_descendant_for_range(r:range()))
local id = node:id()
if not injections[id] or r:byte_length() > injections[id].root:byte_length() then
@ -109,6 +114,7 @@ function TSTreeView:new(bufnr, lang)
end
end
end
end
end)
local nodes = traverse(root, 0, nil, parser:lang(), injections, {})