From 60af1a1db285e1cf2b73d1e5934b044b697287f1 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Sat, 12 Apr 2025 15:51:29 -0700 Subject: [PATCH] fix(treesitter): clear parse options state #33437 Apparently after parsing with options in tree-sitter, the options data persists in the parser object, and thus successive calls to `ts_parser_parse()` will act like `ts_parser_parse_with_options()`. This is problematic because `languagetree.lua` makes coroutine-environment assumptions based on if a nullptr has been returned by the parser function. This commit makes it so that the parse options state is reset upon a regular parse (would be nice if this was done upstream). Fixes #33277 --- src/nvim/lua/treesitter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 5d3599920e..4c39cb332f 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -545,7 +545,8 @@ static int parser_parse(lua_State *L) .progress_callback = on_parser_progress }; new_tree = ts_parser_parse_with_options(p, old_tree, input, parse_options); } else { - new_tree = ts_parser_parse(p, old_tree, input); + // Tree-sitter retains parse options after use, so we must explicitly reset them here. + new_tree = ts_parser_parse_with_options(p, old_tree, input, (TSParseOptions) { 0 }); } break;