From 4c333fdbb7bee299f36624b429f5c065470e421d Mon Sep 17 00:00:00 2001 From: Rodrigodd Date: Thu, 5 Jun 2025 21:28:28 -0300 Subject: [PATCH] test(treesitter): test node access after tree edit --- test/functional/treesitter/node_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 2f6f810ef2..dcea8a5585 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -205,4 +205,27 @@ describe('treesitter node API', function() eq('b', lua_eval('vim.treesitter.get_node_text(children_by_field[2], 0)')) eq('c', lua_eval('vim.treesitter.get_node_text(children_by_field[3], 0)')) end) + + it('node access after tree edit', function() + insert([[ + function x() + return true + end + ]]) + exec_lua(function() + local tree = vim.treesitter.get_parser(0, 'lua'):parse()[1] + + -- ensure treesitter does not try to edit the tree inplace + tree:copy() + + local node = tree:root():child(0) + vim.api.nvim_buf_set_lines(0, 1, 2, false, {}) + vim.schedule(function() + collectgarbage() + local a, b, c, d = node:range() + _G.range = { a, b, c, d } + end) + end) + eq({ 0, 0, 2, 3 }, lua_eval('range')) + end) end)