From 77be44563acb64a481d48f45c8dbbfca2d7db415 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Sun, 2 Feb 2025 03:46:26 -0800 Subject: refactor(treesitter): always return valid range from parse() #32273 Problem: When running an initial parse, parse() returns an empty table rather than an actual range. In `languagetree.lua`, we manually check if a parse was incremental to determine the changed parse region. Solution: - Always return a range (in the C side) from parse(). - Simplify the language tree code a bit. - Logger no longer shows empty ranges on the initial parse. --- src/nvim/lua/treesitter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index c7999ac077..3e33fcd142 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -500,7 +500,8 @@ static int parser_parse(lua_State *L) // The new tree will be pushed to the stack, without copy, ownership is now to the lua GC. // Old tree is owned by lua GC since before uint32_t n_ranges = 0; - TSRange *changed = old_tree ? ts_tree_get_changed_ranges(old_tree, new_tree, &n_ranges) : NULL; + TSRange *changed = old_tree ? ts_tree_get_changed_ranges(old_tree, new_tree, &n_ranges) + : ts_tree_included_ranges(new_tree, &n_ranges); push_tree(L, new_tree); // [tree] -- cgit