diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-03-10 13:35:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 13:35:07 +0000 |
commit | 845efb8e12cb014b385deac62fb83622a99024ec (patch) | |
tree | 3686fc9ffbdd4bd2afeb4419ff649ef6e0f34c55 /src | |
parent | 75537768ef0b8cc35ef9c6aa906237e449640b46 (diff) | |
parent | 46b73bf22cb951151de9bf0712d42e194000b677 (diff) | |
download | rneovim-845efb8e12cb014b385deac62fb83622a99024ec.tar.gz rneovim-845efb8e12cb014b385deac62fb83622a99024ec.tar.bz2 rneovim-845efb8e12cb014b385deac62fb83622a99024ec.zip |
Merge pull request #22594 from lewis6991/perf/treefold
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/lua/stdlib.c | 36 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 4 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index d9682ff63d..b6e56c35d6 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -26,6 +26,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_eval.h" +#include "nvim/fold.h" #include "nvim/globals.h" #include "nvim/lua/converter.h" #include "nvim/lua/spell.h" @@ -528,6 +529,31 @@ static int nlua_iconv(lua_State *lstate) return 1; } +// Like 'zx' but don't call newFoldLevel() +static int nlua_foldupdate(lua_State *lstate) +{ + curwin->w_foldinvalid = true; // recompute folds + foldOpenCursor(); + + return 0; +} + +// Access to internal functions. For use in runtime/ +static void nlua_state_add_internal(lua_State *const lstate) +{ + // _getvar + lua_pushcfunction(lstate, &nlua_getvar); + lua_setfield(lstate, -2, "_getvar"); + + // _setvar + lua_pushcfunction(lstate, &nlua_setvar); + lua_setfield(lstate, -2, "_setvar"); + + // _updatefolds + lua_pushcfunction(lstate, &nlua_foldupdate); + lua_setfield(lstate, -2, "_foldupdate"); +} + void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) { if (!is_thread) { @@ -562,14 +588,6 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) lua_setfield(lstate, -2, "__index"); // [meta] lua_pop(lstate, 1); // don't use metatable now - // _getvar - lua_pushcfunction(lstate, &nlua_getvar); - lua_setfield(lstate, -2, "_getvar"); - - // _setvar - lua_pushcfunction(lstate, &nlua_setvar); - lua_setfield(lstate, -2, "_setvar"); - // vim.spell luaopen_spell(lstate); lua_setfield(lstate, -2, "spell"); @@ -578,6 +596,8 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) // depends on p_ambw, p_emoji lua_pushcfunction(lstate, &nlua_iconv); lua_setfield(lstate, -2, "iconv"); + + nlua_state_add_internal(lstate); } // vim.mpack diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index ae69f3f120..289a0cb9b4 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -405,8 +405,6 @@ static int parser_parse(lua_State *L) old_tree = tmp ? *tmp : NULL; } - bool include_bytes = (lua_gettop(L) >= 3) && lua_toboolean(L, 3); - TSTree *new_tree = NULL; size_t len; const char *str; @@ -443,6 +441,8 @@ static int parser_parse(lua_State *L) return luaL_argerror(L, 3, "expected either string or buffer handle"); } + bool include_bytes = (lua_gettop(L) >= 4) && lua_toboolean(L, 4); + // Sometimes parsing fails (timeout, or wrong parser ABI) // In those case, just return an error. if (!new_tree) { |