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.
This commit is contained in:
Riley Bruins
2025-02-02 03:46:26 -08:00
committed by GitHub
parent 02ea0e77a1
commit 77be44563a
2 changed files with 3 additions and 5 deletions

View File

@ -378,10 +378,7 @@ function LanguageTree:_parse_regions(range, timeout)
return changes, no_regions_parsed, total_parse_time, false
end
-- Pass ranges if this is an initial parse
local cb_changes = self._trees[i] and tree_changes or tree:included_ranges(true)
self:_do_callback('changedtree', cb_changes, tree)
self:_do_callback('changedtree', tree_changes, tree)
self._trees[i] = tree
vim.list_extend(changes, tree_changes)

View File

@ -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]