mirror of
https://github.com/neovim/neovim.git
synced 2026-02-07 04:17:22 +00:00
Problem: TSNode contains a `const TSTree*` and a `const void *id`. The `id` points to Tree-sitter's internal type `Subtree`, which resides inside the `TSTree` but may be deallocated if the `TSTree` is mutated (which is likely why it is `const`). The Lua method `TSTree:edit()` mutates the tree, which can deallocate `id`. See #25254 and #31758. Solution: To avoid this, we now make a copy of the tree before pushing its root to the Lua stack. This also removes the fenv from TSLuaTree, as it was only used when pushing the tree root to the Lua stack. We also copy the tree in `node_tree`. `ts_tree_copy()` just increments a couple of reference counters, so it's relatively cheap to call.