commit 284b0e4fa25c0acc12a88398112fc35aec8791ee
parent 223ac7782e24c3d662185b5f1fc63d718c4376bc
Author: yuukibarns <yuukibarns@gmail.com>
Date: Sun, 30 Mar 2025 23:06:16 +0800
fix(treesitter): fix `:InspectTree` incorrect injections
Diffstat:
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/runtime/lua/vim/treesitter/dev.lua b/runtime/lua/vim/treesitter/dev.lua
@@ -1,5 +1,7 @@
local api = vim.api
+local Range = require('vim.treesitter._range')
+
local M = {}
---@class (private) vim.treesitter.dev.TSTreeView
@@ -96,16 +98,20 @@ 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 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
- injections[id] = {
- lang = child:lang(),
- root = r,
- }
+ 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
+ injections[id] = {
+ lang = child:lang(),
+ root = r,
+ }
+ end
end
end
end