From bd4ca22d0334a3323313dfd6975a80218ec65e36 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Fri, 20 Dec 2024 16:23:52 -0800 Subject: feat(treesitter)!: don't parse tree in get_parser() or start() **Problem:** `vim.treesitter.get_parser()` and `vim.treesitter.start()` both parse the tree before returning it. This is problematic because if this is a sync parse, it will stall the editor on large files. If it is an async parse, the functions return stale trees. **Solution:** Remove this parsing side effect and leave it to the user to parse the returned trees, either synchronously or asynchronously. --- test/functional/treesitter/node_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/treesitter/node_spec.lua') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index c87a56b160..9839022c5e 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -20,6 +20,7 @@ describe('treesitter node API', function() insert('F') exec_lua(function() vim.treesitter.start(0, 'lua') + vim.treesitter.get_parser(0):parse() vim.treesitter.get_node():tree() vim.treesitter.get_node():tree() collectgarbage() @@ -45,6 +46,7 @@ describe('treesitter node API', function() -- this buffer doesn't have filetype set! insert('local foo = function() end') exec_lua(function() + vim.treesitter.get_parser(0, 'lua'):parse() _G.node = vim.treesitter.get_node({ bufnr = 0, pos = { 0, 6 }, -- on "foo" -- cgit