fix(treesitter): ensure TSLuaTree is always immutable

Problem:

The previous fix in #34314 relies on copying the tree in `tree_root` to
ensure the `TSNode`'s tree cannot be mutated. But that causes the
problem where two calls to `tree_root` return nodes from different
copies of a tree, which do not compare as equal. This has broken at
least one plugin.

Solution:

Make all `TSTree`s on the Lua side always immutable, avoiding the need
to copy the tree in `tree_root`, and make the only mutation point,
`tree_edit`, copy the tree instead.
This commit is contained in:
Rodrigodd
2025-06-26 19:45:28 -03:00
committed by Lewis Russell
parent 94f44d58fd
commit 168bf0024e
3 changed files with 26 additions and 20 deletions

View File

@@ -26,6 +26,7 @@ function TSTree:root() end
---@param end_col_old integer
---@param end_row_new integer
---@param end_col_new integer
---@return TSTree
---@nodoc
function TSTree:edit(start_byte, end_byte_old, end_byte_new, start_row, start_col, end_row_old, end_col_old, end_row_new, end_col_new) end

View File

@@ -1107,8 +1107,8 @@ function LanguageTree:_edit(
end_row_new,
end_col_new
)
for _, tree in pairs(self._trees) do
tree:edit(
for i, tree in pairs(self._trees) do
self._trees[i] = tree:edit(
start_byte,
end_byte_old,
end_byte_new,