From 45e606b1fddbfeee8fe28385b5371ca6f2fba71b Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Wed, 18 Dec 2024 10:48:33 -0800 Subject: feat(treesitter): async parsing **Problem:** Parsing can be slow for large files, and it is a blocking operation which can be disruptive and annoying. **Solution:** Provide a function for asynchronous parsing, which accepts a callback to be run after parsing completes. Co-authored-by: Lewis Russell Co-authored-by: Luuk van Baal Co-authored-by: VanaIgr --- src/nvim/lua/treesitter.c | 6 +++++- src/nvim/options.lua | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 28ad2cf4d3..9bd2baad27 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -489,7 +489,11 @@ static int parser_parse(lua_State *L) // Sometimes parsing fails (timeout, or wrong parser ABI) // In those case, just return an error. if (!new_tree) { - return luaL_error(L, "An error occurred when parsing."); + if (ts_parser_timeout_micros(p) == 0) { + // No timeout set, must have had an error + return luaL_error(L, "An error occurred when parsing."); + } + return 0; } // The new tree will be pushed to the stack, without copy, ownership is now to the lua GC. diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 863f875d9d..15a4e8ddc2 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -6520,8 +6520,8 @@ return { defaults = { if_true = 2000 }, desc = [=[ Time in milliseconds for redrawing the display. Applies to - 'hlsearch', 'inccommand', |:match| highlighting and syntax - highlighting. + 'hlsearch', 'inccommand', |:match| highlighting, syntax highlighting, + and async |LanguageTree:parse()|. When redrawing takes more than this many milliseconds no further matches will be highlighted. For syntax highlighting the time applies per window. When over the -- cgit