From d6d6ab3f8e77d54c8030c0c18f17d3c72ac4445c Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 26 Feb 2022 15:19:10 +0100 Subject: feat(lua): low-level interpreter mode (nvim -ll) --- src/nvim/lua/executor.c | 67 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 18 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 5ffd90fddd..d144a5ae23 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -64,6 +64,7 @@ #include "nvim/window.h" static int in_fast_callback = 0; +static bool in_script = false; // Initialized in nlua_init(). static lua_State *global_lstate = NULL; @@ -133,8 +134,13 @@ static void nlua_error(lua_State *const lstate, const char *const msg) str = lua_tolstring(lstate, -1, &len); } - msg_ext_set_kind("lua_error"); - semsg_multiline(msg, (int)len, str); + if (in_script) { + os_errmsg(str); + os_errmsg("\n"); + } else { + msg_ext_set_kind("lua_error"); + semsg_multiline(msg, (int)len, str); + } lua_pop(lstate, 1); } @@ -534,7 +540,7 @@ int nlua_get_global_ref_count(void) return nlua_global_refs->ref_count; } -static void nlua_common_vim_init(lua_State *lstate, bool is_thread) +static void nlua_common_vim_init(lua_State *lstate, bool is_thread, bool is_standalone) FUNC_ATTR_NONNULL_ARG(1) { nlua_ref_state_t *ref_state = nlua_new_ref_state(lstate, is_thread); @@ -567,7 +573,9 @@ static void nlua_common_vim_init(lua_State *lstate, bool is_thread) lua_setfield(lstate, -2, "_empty_dict_mt"); // vim.loop - if (is_thread) { + if (is_standalone) { + // do nothing, use libluv like in a standalone interpreter + } else if (is_thread) { luv_set_callback(lstate, nlua_luv_thread_cb_cfpcall); luv_set_thread(lstate, nlua_luv_thread_cfpcall); luv_set_cthread(lstate, nlua_luv_thread_cfcpcall); @@ -606,7 +614,7 @@ static int nlua_module_preloader(lua_State *lstate) return 1; } -static bool nlua_init_packages(lua_State *lstate) +static bool nlua_init_packages(lua_State *lstate, bool is_standalone) FUNC_ATTR_NONNULL_ALL { // put builtin packages in preload @@ -618,7 +626,7 @@ static bool nlua_init_packages(lua_State *lstate) lua_pushcclosure(lstate, nlua_module_preloader, 1); // [package, preload, cclosure] lua_setfield(lstate, -2, def.name); // [package, preload] - if (nlua_disable_preload && strequal(def.name, "vim.inspect")) { + if ((nlua_disable_preload && !is_standalone) && strequal(def.name, "vim.inspect")) { break; } } @@ -769,7 +777,7 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pushcfunction(lstate, &nlua_ui_detach); lua_setfield(lstate, -2, "ui_detach"); - nlua_common_vim_init(lstate, false); + nlua_common_vim_init(lstate, false, false); // patch require() (only for --startuptime) if (time_fd != NULL) { @@ -788,7 +796,7 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_setglobal(lstate, "vim"); - if (!nlua_init_packages(lstate)) { + if (!nlua_init_packages(lstate, false)) { return false; } @@ -823,10 +831,29 @@ void nlua_init(char **argv, int argc, int lua_arg0) } static lua_State *nlua_thread_acquire_vm(void) +{ + return nlua_init_state(true); +} + +void nlua_run_script(char **argv, int argc, int lua_arg0) + FUNC_ATTR_NORETURN +{ + in_script = true; + global_lstate = nlua_init_state(false); + luv_set_thread_cb(nlua_thread_acquire_vm, nlua_common_free_all_mem); + nlua_init_argv(global_lstate, argv, argc, lua_arg0); + bool lua_ok = nlua_exec_file(argv[lua_arg0 - 1]); +#ifdef EXITFREE + nlua_free_all_mem(); +#endif + exit(lua_ok ? 0 : 1); +} + +lua_State *nlua_init_state(bool thread) { // If it is called from the main thread, it will attempt to rebuild the cache. const uv_thread_t self = uv_thread_self(); - if (uv_thread_equal(&main_thread, &self)) { + if (!in_script && uv_thread_equal(&main_thread, &self)) { runtime_search_path_validate(); } @@ -835,9 +862,11 @@ static lua_State *nlua_thread_acquire_vm(void) // Add in the lua standard libraries luaL_openlibs(lstate); - // print - lua_pushcfunction(lstate, &nlua_print); - lua_setglobal(lstate, "print"); + if (!in_script) { + // print + lua_pushcfunction(lstate, &nlua_print); + lua_setglobal(lstate, "print"); + } lua_pushinteger(lstate, 0); lua_setfield(lstate, LUA_REGISTRYINDEX, "nlua.refcount"); @@ -845,18 +874,20 @@ static lua_State *nlua_thread_acquire_vm(void) // vim lua_newtable(lstate); - nlua_common_vim_init(lstate, true); + nlua_common_vim_init(lstate, thread, in_script); nlua_state_add_stdlib(lstate, true); - lua_createtable(lstate, 0, 0); - lua_pushcfunction(lstate, nlua_thr_api_nvim__get_runtime); - lua_setfield(lstate, -2, "nvim__get_runtime"); - lua_setfield(lstate, -2, "api"); + if (!in_script) { + lua_createtable(lstate, 0, 0); + lua_pushcfunction(lstate, nlua_thr_api_nvim__get_runtime); + lua_setfield(lstate, -2, "nvim__get_runtime"); + lua_setfield(lstate, -2, "api"); + } lua_setglobal(lstate, "vim"); - nlua_init_packages(lstate); + nlua_init_packages(lstate, in_script); lua_getglobal(lstate, "package"); lua_getfield(lstate, -1, "loaded"); -- cgit From 42999a8d645ccf880222f0192671b8ce01bde361 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 30 Jan 2023 14:46:28 +0100 Subject: fix(test): fix issues detected by running unittests in ASAN/UBSAN --- src/nvim/lua/executor.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index d144a5ae23..1415ceeaed 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -821,6 +821,9 @@ void nlua_init(char **argv, int argc, int lua_arg0) luaL_openlibs(lstate); if (!nlua_state_init(lstate)) { os_errmsg(_("E970: Failed to initialize builtin lua modules\n")); +#ifdef EXITFREE + nlua_common_free_all_mem(lstate); +#endif os_exit(1); } -- cgit From 69bb145cea56067e6e82ed0a130a51c0d611e540 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Feb 2023 20:14:31 +0800 Subject: refactor(exit): pass error message to preserve_exit() (#22097) Problem: 1. Some calls to preserve_exit() don't put a message in IObuff, so the IObuff printed by preserve_exit() contains unrelated information. 2. If a TUI client runs out of memory or receives a deadly signal, the error message is shown on alternate screen and cannot be easily seen because the TUI exits alternate screen soon afterwards. Solution: Pass error message to preserve_exit() and exit alternate screen before printing it. Note that this doesn't fix the problem that server error messages cannot be easily seen on exit. This is tracked in #21608 and #21843. --- src/nvim/lua/executor.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 1415ceeaed..007662fbc9 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -211,9 +211,7 @@ static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags if (status) { if (status == LUA_ERRMEM && !(flags & LUVF_CALLBACK_NOEXIT)) { // consider out of memory errors unrecoverable, just like xmalloc() - os_errmsg(e_outofmem); - os_errmsg("\n"); - preserve_exit(); + preserve_exit(e_outofmem); } const char *error = lua_tostring(lstate, -1); -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/lua/stdlib.c | 14 +++++++------- src/nvim/lua/treesitter.c | 16 ++++++++-------- src/nvim/lua/xdiff.c | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 6ebca6d97e..73246f81b7 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -78,20 +78,20 @@ static int regex_match_line(lua_State *lstate) return luaL_error(lstate, "not enough args"); } - long bufnr = luaL_checkinteger(lstate, 2); + handle_T bufnr = (handle_T)luaL_checkinteger(lstate, 2); linenr_T rownr = (linenr_T)luaL_checkinteger(lstate, 3); - long start = 0, end = -1; + int start = 0, end = -1; if (narg >= 4) { - start = luaL_checkinteger(lstate, 4); + start = (int)luaL_checkinteger(lstate, 4); } if (narg >= 5) { - end = luaL_checkinteger(lstate, 5); + end = (int)luaL_checkinteger(lstate, 5); if (end < 0) { return luaL_error(lstate, "invalid end"); } } - buf_T *buf = bufnr ? handle_get_buffer((int)bufnr) : curbuf; + buf_T *buf = bufnr ? handle_get_buffer(bufnr) : curbuf; if (!buf || buf->b_ml.ml_mfp == NULL) { return luaL_error(lstate, "invalid buffer"); } @@ -218,7 +218,7 @@ static int nlua_str_utf_start(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL { size_t s1_len; const char *s1 = luaL_checklstring(lstate, 1, &s1_len); - long offset = luaL_checkinteger(lstate, 2); + ptrdiff_t offset = luaL_checkinteger(lstate, 2); if (offset < 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } @@ -238,7 +238,7 @@ static int nlua_str_utf_end(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL { size_t s1_len; const char *s1 = luaL_checklstring(lstate, 1, &s1_len); - long offset = luaL_checkinteger(lstate, 2); + ptrdiff_t offset = luaL_checkinteger(lstate, 2); if (offset < 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 56f4daed1a..5248ebed14 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -393,7 +393,7 @@ static int parser_parse(lua_State *L) TSTree *new_tree = NULL; size_t len; const char *str; - long bufnr; + handle_T bufnr; buf_T *buf; TSInput input; @@ -406,13 +406,13 @@ static int parser_parse(lua_State *L) break; case LUA_TNUMBER: - bufnr = lua_tointeger(L, 3); - buf = handle_get_buffer((handle_T)bufnr); + bufnr = (handle_T)lua_tointeger(L, 3); + buf = handle_get_buffer(bufnr); if (!buf) { #define BUFSIZE 256 char ebuf[BUFSIZE] = { 0 }; - vim_snprintf(ebuf, BUFSIZE, "invalid buffer handle: %ld", bufnr); + vim_snprintf(ebuf, BUFSIZE, "invalid buffer handle: %d", bufnr); return luaL_argerror(L, 3, ebuf); #undef BUFSIZE } @@ -898,8 +898,8 @@ static int node_child(lua_State *L) if (!node_check(L, 1, &node)) { return 0; } - long num = lua_tointeger(L, 2); - TSNode child = ts_node_child(node, (uint32_t)num); + uint32_t num = (uint32_t)lua_tointeger(L, 2); + TSNode child = ts_node_child(node, num); push_node(L, child, 1); return 1; @@ -911,8 +911,8 @@ static int node_named_child(lua_State *L) if (!node_check(L, 1, &node)) { return 0; } - long num = lua_tointeger(L, 2); - TSNode child = ts_node_named_child(node, (uint32_t)num); + uint32_t num = (uint32_t)lua_tointeger(L, 2); + TSNode child = ts_node_named_child(node, num); push_node(L, child, 1); return 1; diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 857b159af5..9a7ae5c146 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -257,13 +257,13 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, if (check_xdiff_opt(v->type, kObjectTypeInteger, "ctxlen", err)) { goto exit_1; } - cfg->ctxlen = v->data.integer; + cfg->ctxlen = (long)v->data.integer; } else if (strequal("interhunkctxlen", k.data)) { if (check_xdiff_opt(v->type, kObjectTypeInteger, "interhunkctxlen", err)) { goto exit_1; } - cfg->interhunkctxlen = v->data.integer; + cfg->interhunkctxlen = (long)v->data.integer; } else if (strequal("linematch", k.data)) { *linematch = api_object_to_bool(*v, "linematch", false, err); if (ERROR_SET(err)) { -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/lua/executor.c | 2 +- src/nvim/lua/stdlib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 007662fbc9..5fbbb342bf 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1993,7 +1993,7 @@ char *nlua_register_table_as_callable(const typval_T *const arg) void nlua_execute_on_key(int c) { char buf[NUMBUFLEN]; - size_t buf_len = special_to_buf(c, mod_mask, false, (char_u *)buf); + size_t buf_len = special_to_buf(c, mod_mask, false, buf); lua_State *const lstate = global_lstate; diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 73246f81b7..5aeff4de98 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -222,7 +222,7 @@ static int nlua_str_utf_start(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL if (offset < 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } - int head_offset = utf_cp_head_off((char_u *)s1, (char_u *)s1 + offset - 1); + int head_offset = utf_cp_head_off(s1, s1 + offset - 1); lua_pushinteger(lstate, head_offset); return 1; } -- cgit From 27177e581902967dcf4f2f426464da1b636ca420 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:14:24 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22211) --- src/nvim/lua/executor.c | 3 +-- src/nvim/lua/spell.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 5fbbb342bf..c8fc76e20d 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1766,13 +1766,12 @@ bool nlua_exec_file(const char *path) StringBuilder sb = KV_INITIAL_VALUE; kv_resize(sb, 64); - ptrdiff_t read_size = -1; // Read all input from stdin, unless interrupted (ctrl-c). while (true) { if (got_int) { // User canceled. return false; } - read_size = file_read(stdin_dup, IObuff, 64); + ptrdiff_t read_size = file_read(stdin_dup, IObuff, 64); if (read_size < 0) { // Error. return false; } diff --git a/src/nvim/lua/spell.c b/src/nvim/lua/spell.c index d510d25e90..78e023c26d 100644 --- a/src/nvim/lua/spell.c +++ b/src/nvim/lua/spell.c @@ -51,7 +51,6 @@ int nlua_spell_check(lua_State *lstate) } hlf_T attr = HLF_COUNT; - size_t len = 0; size_t pos = 0; int capcol = -1; int no_res = 0; @@ -61,7 +60,7 @@ int nlua_spell_check(lua_State *lstate) while (*str != NUL) { attr = HLF_COUNT; - len = spell_check(curwin, (char *)str, &attr, &capcol, false); + size_t len = spell_check(curwin, (char *)str, &attr, &capcol, false); assert(len <= INT_MAX); if (attr != HLF_COUNT) { -- cgit From 799edca18a4ddcf8edcb63dd391219e01e187f0d Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 28 Nov 2022 22:43:10 +0100 Subject: feat(lua): make sure require'bit' always works, even with PUC lua 5.1 --- src/nvim/lua/stdlib.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 5aeff4de98..d9682ff63d 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -11,6 +11,10 @@ #include #include +#ifdef NVIM_VENDOR_BIT +# include "bit.h" +#endif + #include "auto/config.h" #include "cjson/lua_cjson.h" #include "mpack/lmpack.h" @@ -596,6 +600,13 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) // vim.json lua_cjson_new(lstate); lua_setfield(lstate, -2, "json"); + +#ifdef NVIM_VENDOR_BIT + // if building with puc lua, use internal fallback for require'bit' + int top = lua_gettop(lstate); + luaopen_bit(lstate); + lua_settop(lstate, top); +#endif } /// like luaL_error, but allow cleanup -- cgit From 774e59f3f9bf50c8350857c6722bb58df2dd940a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sun, 26 Feb 2023 16:53:33 +0000 Subject: feat(treesitter): expand the API --- src/nvim/lua/treesitter.c | 138 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 15 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 5248ebed14..d72e7a1825 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -51,8 +51,11 @@ static struct luaL_Reg parser_meta[] = { { "__gc", parser_gc }, { "__tostring", parser_tostring }, { "parse", parser_parse }, + { "reset", parser_reset }, { "set_included_ranges", parser_set_ranges }, { "included_ranges", parser_get_ranges }, + { "set_timeout", parser_set_timeout }, + { "timeout", parser_get_timeout }, { NULL, NULL } }; @@ -78,6 +81,8 @@ static struct luaL_Reg node_meta[] = { { "field", node_field }, { "named", node_named }, { "missing", node_missing }, + { "extra", node_extra }, + { "has_changes", node_has_changes }, { "has_error", node_has_error }, { "sexpr", node_sexpr }, { "child_count", node_child_count }, @@ -95,7 +100,9 @@ static struct luaL_Reg node_meta[] = { { "prev_named_sibling", node_prev_named_sibling }, { "named_children", node_named_children }, { "root", node_root }, + { "tree", node_tree }, { "byte_length", node_byte_length }, + { "equal", node_equal }, { NULL, NULL } }; @@ -446,6 +453,16 @@ static int parser_parse(lua_State *L) return 2; } +static int parser_reset(lua_State *L) +{ + TSParser **p = parser_check(L, 1); + if (p && *p) { + ts_parser_reset(*p); + } + + return 0; +} + static int tree_copy(lua_State *L) { TSTree **tree = tree_check(L, 1); @@ -597,6 +614,33 @@ static int parser_get_ranges(lua_State *L) return 1; } +static int parser_set_timeout(lua_State *L) +{ + TSParser **p = parser_check(L, 1); + if (!p) { + return 0; + } + + if (lua_gettop(L) < 2) { + luaL_error(L, "integer expected"); + } + + uint32_t timeout = (uint32_t)luaL_checkinteger(L, 2); + ts_parser_set_timeout_micros(*p, timeout); + return 0; +} + +static int parser_get_timeout(lua_State *L) +{ + TSParser **p = parser_check(L, 1); + if (!p) { + return 0; + } + + lua_pushinteger(L, (long)ts_parser_timeout_micros(*p)); + return 0; +} + // Tree methods /// push tree interface on lua stack. @@ -740,12 +784,29 @@ static int node_range(lua_State *L) if (!node_check(L, 1, &node)) { return 0; } + + bool include_bytes = false; + if (lua_gettop(L) >= 2) { + include_bytes = lua_toboolean(L, 2); + } + TSPoint start = ts_node_start_point(node); TSPoint end = ts_node_end_point(node); - lua_pushnumber(L, start.row); - lua_pushnumber(L, start.column); - lua_pushnumber(L, end.row); - lua_pushnumber(L, end.column); + + if (include_bytes) { + lua_pushinteger(L, start.row); + lua_pushinteger(L, start.column); + lua_pushinteger(L, ts_node_start_byte(node)); + lua_pushinteger(L, end.row); + lua_pushinteger(L, end.column); + lua_pushinteger(L, ts_node_end_byte(node)); + return 6; + } + + lua_pushinteger(L, start.row); + lua_pushinteger(L, start.column); + lua_pushinteger(L, end.row); + lua_pushinteger(L, end.column); return 4; } @@ -757,9 +818,9 @@ static int node_start(lua_State *L) } TSPoint start = ts_node_start_point(node); uint32_t start_byte = ts_node_start_byte(node); - lua_pushnumber(L, start.row); - lua_pushnumber(L, start.column); - lua_pushnumber(L, start_byte); + lua_pushinteger(L, start.row); + lua_pushinteger(L, start.column); + lua_pushinteger(L, start_byte); return 3; } @@ -771,9 +832,9 @@ static int node_end(lua_State *L) } TSPoint end = ts_node_end_point(node); uint32_t end_byte = ts_node_end_byte(node); - lua_pushnumber(L, end.row); - lua_pushnumber(L, end.column); - lua_pushnumber(L, end_byte); + lua_pushinteger(L, end.row); + lua_pushinteger(L, end.column); + lua_pushinteger(L, end_byte); return 3; } @@ -784,7 +845,7 @@ static int node_child_count(lua_State *L) return 0; } uint32_t count = ts_node_child_count(node); - lua_pushnumber(L, count); + lua_pushinteger(L, count); return 1; } @@ -795,7 +856,7 @@ static int node_named_child_count(lua_State *L) return 0; } uint32_t count = ts_node_named_child_count(node); - lua_pushnumber(L, count); + lua_pushinteger(L, count); return 1; } @@ -816,7 +877,7 @@ static int node_symbol(lua_State *L) return 0; } TSSymbol symbol = ts_node_symbol(node); - lua_pushnumber(L, symbol); + lua_pushinteger(L, symbol); return 1; } @@ -882,6 +943,26 @@ static int node_missing(lua_State *L) return 1; } +static int node_extra(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + lua_pushboolean(L, ts_node_is_extra(node)); + return 1; +} + +static int node_has_changes(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + lua_pushboolean(L, ts_node_has_changes(node)); + return 1; +} + static int node_has_error(lua_State *L) { TSNode node; @@ -1108,6 +1189,17 @@ static int node_root(lua_State *L) return 1; } +static int node_tree(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + + push_tree(L, (TSTree *)node.tree, false); + return 1; +} + static int node_byte_length(lua_State *L) { TSNode node; @@ -1118,7 +1210,23 @@ static int node_byte_length(lua_State *L) uint32_t start_byte = ts_node_start_byte(node); uint32_t end_byte = ts_node_end_byte(node); - lua_pushnumber(L, end_byte - start_byte); + lua_pushinteger(L, end_byte - start_byte); + return 1; +} + +static int node_equal(lua_State *L) +{ + TSNode node1; + if (!node_check(L, 1, &node1)) { + return 0; + } + + TSNode node2; + if (!node_check(L, 2, &node2)) { + return luaL_error(L, "TSNode expected"); + } + + lua_pushboolean(L, ts_node_eq(node1, node2)); return 1; } @@ -1367,7 +1475,7 @@ static int query_inspect(lua_State *L) &strlen); lua_pushlstring(L, str, strlen); // [retval, patterns, pat, pred, item] } else if (step[k].type == TSQueryPredicateStepTypeCapture) { - lua_pushnumber(L, step[k].value_id + 1); // [..., pat, pred, item] + lua_pushinteger(L, step[k].value_id + 1); // [..., pat, pred, item] } else { abort(); } -- cgit From c002fd421e3d8deb4adf144cadcd3a6fe4635e12 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 27 Feb 2023 19:41:40 +0100 Subject: refactor(build): graduate libtreesitter features which are 1+ years old --- src/nvim/lua/treesitter.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index d72e7a1825..2db12b8ded 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -152,9 +152,7 @@ void tslua_init(lua_State *L) build_meta(L, TS_META_QUERYCURSOR, querycursor_meta); build_meta(L, TS_META_TREECURSOR, treecursor_meta); -#ifdef NVIM_TS_HAS_SET_ALLOCATOR ts_set_allocator(xmalloc, xcalloc, xrealloc, xfree); -#endif } int tslua_has_language(lua_State *L) @@ -1321,11 +1319,7 @@ static int node_rawquery(lua_State *L) } else { cursor = ts_query_cursor_new(); } - // TODO(clason): API introduced after tree-sitter release 0.19.5 - // remove guard when minimum ts version is bumped to 0.19.6+ -#ifdef NVIM_TS_HAS_SET_MATCH_LIMIT ts_query_cursor_set_match_limit(cursor, 64); -#endif ts_query_cursor_exec(cursor, query, node); bool captures = lua_toboolean(L, 3); -- cgit From 7e90f247e7b3add74a49895054a543c2140bbb08 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 3 Mar 2023 16:16:17 +0100 Subject: fix(treesitter): raise ts_match_limit to 256 (#22497) Problem: Some complex queries may not return all matches. Solution: Raise `ts_match_limit` from current 64 (twice the original default) to 256 (which Helix uses, and seems to be enough for the reported problematic cases). If this leads performance regressions in other queries, we should add a generic querying timeout instead of relying on a low value here. --- src/nvim/lua/treesitter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 2db12b8ded..4cbe7329a6 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -1319,7 +1319,7 @@ static int node_rawquery(lua_State *L) } else { cursor = ts_query_cursor_new(); } - ts_query_cursor_set_match_limit(cursor, 64); + ts_query_cursor_set_match_limit(cursor, 256); ts_query_cursor_exec(cursor, query, node); bool captures = lua_toboolean(L, 3); -- cgit From 808691e3993ee54519229c175fb950cc02261287 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 12:08:45 +0800 Subject: fix(luado): get old_line length before executing Lua code --- src/nvim/lua/executor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index c8fc76e20d..bb461a7f13 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1706,7 +1706,9 @@ void ex_luado(exarg_T *const eap) break; } lua_pushvalue(lstate, -1); - const char *old_line = (const char *)ml_get_buf(curbuf, l, false); + const char *const old_line = (const char *)ml_get_buf(curbuf, l, false); + // Get length of old_line here as calling Lua code may free it. + const size_t old_line_len = strlen(old_line); lua_pushstring(lstate, old_line); lua_pushnumber(lstate, (lua_Number)l); if (nlua_pcall(lstate, 2, 1)) { @@ -1714,8 +1716,6 @@ void ex_luado(exarg_T *const eap) break; } if (lua_isstring(lstate, -1)) { - size_t old_line_len = strlen(old_line); - size_t new_line_len; const char *const new_line = lua_tolstring(lstate, -1, &new_line_len); char *const new_line_transformed = xmemdupz(new_line, new_line_len); -- cgit From 0e7196438d8f856eecd7c90e160b79cbc8fb08dc Mon Sep 17 00:00:00 2001 From: Kelly Lin Date: Sun, 19 Feb 2023 22:33:57 +1100 Subject: feat(lua): add semver api --- src/nvim/lua/executor.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index bb461a7f13..5ec91aebb0 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -165,17 +165,6 @@ static int nlua_pcall(lua_State *lstate, int nargs, int nresults) return status; } -/// Gets the version of the current Nvim build. -/// -/// @param lstate Lua interpreter state. -static int nlua_nvim_version(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL -{ - Dictionary version = version_dict(); - nlua_push_Dictionary(lstate, version, true); - api_free_dictionary(version); - return 1; -} - static void nlua_luv_error_event(void **argv) { char *error = (char *)argv[0]; @@ -739,10 +728,6 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL // vim.types, vim.type_idx, vim.val_idx nlua_init_types(lstate); - // neovim version - lua_pushcfunction(lstate, &nlua_nvim_version); - lua_setfield(lstate, -2, "version"); - // schedule lua_pushcfunction(lstate, &nlua_schedule); lua_setfield(lstate, -2, "schedule"); -- cgit From 79571b92ced968ad27bee2a7515a4a04e84dbad2 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 27 Jan 2021 09:00:28 +0100 Subject: feat(lua): omnifunc for builting lua interpreter also make implicit submodules "uri" and "_inspector" work with completion this is needed for `:lua=vim.uri_` wildmenu completion to work even before uri or _inspector functions are used. --- src/nvim/lua/executor.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index bb461a7f13..8a50c8fe4f 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1872,6 +1872,12 @@ int nlua_expand_pat(expand_T *xp, char *pat, int *num_results, char ***results) lua_getfield(lstate, -1, "_expand_pat"); luaL_checktype(lstate, -1, LUA_TFUNCTION); + // ex expansion prepends a ^, but don't worry, it is not a regex + if (pat[0] != '^') { + return FAIL; + } + pat++; + // [ vim, vim._expand_pat, buf ] lua_pushlstring(lstate, (const char *)pat, strlen(pat)); -- cgit From 276b647fdba07bf1762d8dd371c4b655b8a418df Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 8 Mar 2023 17:22:28 +0000 Subject: refactor(treesitter): delegate region calculation to treesitter (#22553) --- src/nvim/lua/treesitter.c | 54 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 4cbe7329a6..104fa5f3e9 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -64,6 +64,7 @@ static struct luaL_Reg tree_meta[] = { { "__tostring", tree_tostring }, { "root", tree_root }, { "edit", tree_edit }, + { "included_ranges", tree_get_ranges }, { "copy", tree_copy }, { NULL, NULL } }; @@ -364,19 +365,29 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position #undef BUFSIZE } -static void push_ranges(lua_State *L, const TSRange *ranges, const size_t length) +static void push_ranges(lua_State *L, const TSRange *ranges, const size_t length, + bool include_bytes) { lua_createtable(L, (int)length, 0); for (size_t i = 0; i < length; i++) { - lua_createtable(L, 4, 0); + lua_createtable(L, include_bytes ? 6 : 4, 0); + int j = 1; lua_pushinteger(L, ranges[i].start_point.row); - lua_rawseti(L, -2, 1); + lua_rawseti(L, -2, j++); lua_pushinteger(L, ranges[i].start_point.column); - lua_rawseti(L, -2, 2); + lua_rawseti(L, -2, j++); + if (include_bytes) { + lua_pushinteger(L, ranges[i].start_byte); + lua_rawseti(L, -2, j++); + } lua_pushinteger(L, ranges[i].end_point.row); - lua_rawseti(L, -2, 3); + lua_rawseti(L, -2, j++); lua_pushinteger(L, ranges[i].end_point.column); - lua_rawseti(L, -2, 4); + lua_rawseti(L, -2, j++); + if (include_bytes) { + lua_pushinteger(L, ranges[i].end_byte); + lua_rawseti(L, -2, j++); + } lua_rawseti(L, -2, (int)(i + 1)); } @@ -395,6 +406,8 @@ 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; @@ -445,7 +458,7 @@ static int parser_parse(lua_State *L) push_tree(L, new_tree, false); // [tree] - push_ranges(L, changed, n_ranges); // [tree, ranges] + push_ranges(L, changed, n_ranges, include_bytes); // [tree, ranges] xfree(changed); return 2; @@ -500,6 +513,24 @@ static int tree_edit(lua_State *L) return 0; } +static int tree_get_ranges(lua_State *L) +{ + TSTree **tree = tree_check(L, 1); + if (!(*tree)) { + return 0; + } + + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); + + uint32_t len; + TSRange *ranges = ts_tree_included_ranges(*tree, &len); + + push_ranges(L, ranges, len, include_bytes); + + xfree(ranges); + return 1; +} + // Use the top of the stack (without popping it) to create a TSRange, it can be // either a lua table or a TSNode static void range_from_lua(lua_State *L, TSRange *range) @@ -605,10 +636,12 @@ static int parser_get_ranges(lua_State *L) return 0; } + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); + uint32_t len; const TSRange *ranges = ts_parser_included_ranges(*p, &len); - push_ranges(L, ranges, len); + push_ranges(L, ranges, len, include_bytes); return 1; } @@ -783,10 +816,7 @@ static int node_range(lua_State *L) return 0; } - bool include_bytes = false; - if (lua_gettop(L) >= 2) { - include_bytes = lua_toboolean(L, 2); - } + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); TSPoint start = ts_node_start_point(node); TSPoint end = ts_node_end_point(node); -- cgit From b9f19d3e286d95d9209afbc479fa2eb908067fb1 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 8 Mar 2023 17:59:45 +0000 Subject: Revert "refactor(treesitter): delegate region calculation to treesitter" (#22575) Revert "refactor(treesitter): delegate region calculation to treesitter (#22553)" This reverts commit 276b647fdba07bf1762d8dd371c4b655b8a418df. --- src/nvim/lua/treesitter.c | 54 +++++++++++------------------------------------ 1 file changed, 12 insertions(+), 42 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 104fa5f3e9..4cbe7329a6 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -64,7 +64,6 @@ static struct luaL_Reg tree_meta[] = { { "__tostring", tree_tostring }, { "root", tree_root }, { "edit", tree_edit }, - { "included_ranges", tree_get_ranges }, { "copy", tree_copy }, { NULL, NULL } }; @@ -365,29 +364,19 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position #undef BUFSIZE } -static void push_ranges(lua_State *L, const TSRange *ranges, const size_t length, - bool include_bytes) +static void push_ranges(lua_State *L, const TSRange *ranges, const size_t length) { lua_createtable(L, (int)length, 0); for (size_t i = 0; i < length; i++) { - lua_createtable(L, include_bytes ? 6 : 4, 0); - int j = 1; + lua_createtable(L, 4, 0); lua_pushinteger(L, ranges[i].start_point.row); - lua_rawseti(L, -2, j++); + lua_rawseti(L, -2, 1); lua_pushinteger(L, ranges[i].start_point.column); - lua_rawseti(L, -2, j++); - if (include_bytes) { - lua_pushinteger(L, ranges[i].start_byte); - lua_rawseti(L, -2, j++); - } + lua_rawseti(L, -2, 2); lua_pushinteger(L, ranges[i].end_point.row); - lua_rawseti(L, -2, j++); + lua_rawseti(L, -2, 3); lua_pushinteger(L, ranges[i].end_point.column); - lua_rawseti(L, -2, j++); - if (include_bytes) { - lua_pushinteger(L, ranges[i].end_byte); - lua_rawseti(L, -2, j++); - } + lua_rawseti(L, -2, 4); lua_rawseti(L, -2, (int)(i + 1)); } @@ -406,8 +395,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; @@ -458,7 +445,7 @@ static int parser_parse(lua_State *L) push_tree(L, new_tree, false); // [tree] - push_ranges(L, changed, n_ranges, include_bytes); // [tree, ranges] + push_ranges(L, changed, n_ranges); // [tree, ranges] xfree(changed); return 2; @@ -513,24 +500,6 @@ static int tree_edit(lua_State *L) return 0; } -static int tree_get_ranges(lua_State *L) -{ - TSTree **tree = tree_check(L, 1); - if (!(*tree)) { - return 0; - } - - bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); - - uint32_t len; - TSRange *ranges = ts_tree_included_ranges(*tree, &len); - - push_ranges(L, ranges, len, include_bytes); - - xfree(ranges); - return 1; -} - // Use the top of the stack (without popping it) to create a TSRange, it can be // either a lua table or a TSNode static void range_from_lua(lua_State *L, TSRange *range) @@ -636,12 +605,10 @@ static int parser_get_ranges(lua_State *L) return 0; } - bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); - uint32_t len; const TSRange *ranges = ts_parser_included_ranges(*p, &len); - push_ranges(L, ranges, len, include_bytes); + push_ranges(L, ranges, len); return 1; } @@ -816,7 +783,10 @@ static int node_range(lua_State *L) return 0; } - bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); + bool include_bytes = false; + if (lua_gettop(L) >= 2) { + include_bytes = lua_toboolean(L, 2); + } TSPoint start = ts_node_start_point(node); TSPoint end = ts_node_end_point(node); -- cgit From ae263aff9547b8b513c4fedaceb4cbf93c57b866 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 9 Mar 2023 16:09:39 +0000 Subject: refactor(treesitter): use byte ranges from treesitter (#22589) --- src/nvim/lua/treesitter.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 4cbe7329a6..ae69f3f120 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -364,19 +364,29 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position #undef BUFSIZE } -static void push_ranges(lua_State *L, const TSRange *ranges, const size_t length) +static void push_ranges(lua_State *L, const TSRange *ranges, const size_t length, + bool include_bytes) { lua_createtable(L, (int)length, 0); for (size_t i = 0; i < length; i++) { - lua_createtable(L, 4, 0); + lua_createtable(L, include_bytes ? 6 : 4, 0); + int j = 1; lua_pushinteger(L, ranges[i].start_point.row); - lua_rawseti(L, -2, 1); + lua_rawseti(L, -2, j++); lua_pushinteger(L, ranges[i].start_point.column); - lua_rawseti(L, -2, 2); + lua_rawseti(L, -2, j++); + if (include_bytes) { + lua_pushinteger(L, ranges[i].start_byte); + lua_rawseti(L, -2, j++); + } lua_pushinteger(L, ranges[i].end_point.row); - lua_rawseti(L, -2, 3); + lua_rawseti(L, -2, j++); lua_pushinteger(L, ranges[i].end_point.column); - lua_rawseti(L, -2, 4); + lua_rawseti(L, -2, j++); + if (include_bytes) { + lua_pushinteger(L, ranges[i].end_byte); + lua_rawseti(L, -2, j++); + } lua_rawseti(L, -2, (int)(i + 1)); } @@ -395,6 +405,8 @@ 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; @@ -445,7 +457,7 @@ static int parser_parse(lua_State *L) push_tree(L, new_tree, false); // [tree] - push_ranges(L, changed, n_ranges); // [tree, ranges] + push_ranges(L, changed, n_ranges, include_bytes); // [tree, ranges] xfree(changed); return 2; @@ -605,10 +617,12 @@ static int parser_get_ranges(lua_State *L) return 0; } + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); + uint32_t len; const TSRange *ranges = ts_parser_included_ranges(*p, &len); - push_ranges(L, ranges, len); + push_ranges(L, ranges, len, include_bytes); return 1; } @@ -783,10 +797,7 @@ static int node_range(lua_State *L) return 0; } - bool include_bytes = false; - if (lua_gettop(L) >= 2) { - include_bytes = lua_toboolean(L, 2); - } + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); TSPoint start = ts_node_start_point(node); TSPoint end = ts_node_end_point(node); -- cgit From 4f75960660f9065214f49ba6ed9176e0a72fa92a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 10 Mar 2023 10:08:06 +0000 Subject: fix(treesitter): correct include_bytes arg for parse() --- src/nvim/lua/treesitter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua') 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) { -- cgit From 46b73bf22cb951151de9bf0712d42e194000b677 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 9 Mar 2023 15:28:55 +0000 Subject: perf(treesitter): more efficient foldexpr --- src/nvim/lua/stdlib.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src/nvim/lua') 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 -- cgit From 402c31a82d2961172c6eaf8014762f28c60bd93e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Mar 2023 17:58:05 +0800 Subject: refactor: move ga_loaded to runtime.c (#22626) --- src/nvim/lua/stdlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index b6e56c35d6..852e10c8d8 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -22,7 +22,6 @@ #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" -#include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_eval.h" @@ -38,6 +37,7 @@ #include "nvim/memory.h" #include "nvim/pos.h" #include "nvim/regexp.h" +#include "nvim/runtime.h" #include "nvim/types.h" #include "nvim/vim.h" -- cgit From 7dc9182cf0b27cbfb4e289db55dd7b02998ef5c8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Mar 2023 21:29:25 +0800 Subject: vim-patch:8.2.1398: autoload script sourced twice if sourced directly (#22622) Problem: Autoload script sourced twice if sourced directly. Solution: Do not source an autoload script again. (issue vim/vim#6644) https://github.com/vim/vim/commit/daa2f36573db3e1df7eb1fdbc3a09a2815644048 Cherry-pick ret_sid changes from patch 8.2.0149. Use do_in_runtimepath() as that's what source_runtime() calls in Nvim. Co-authored-by: Bram Moolenaar --- src/nvim/lua/executor.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 078bc4fea9..11a02ea402 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -2061,10 +2061,15 @@ void nlua_set_sctx(sctx_T *current) break; } char *source_path = fix_fname(info->source + 1); - get_current_script_id(&source_path, current); - xfree(source_path); - current->sc_lnum = info->currentline; + int sid = find_script_by_name(source_path); + if (sid > 0) { + xfree(source_path); + } else { + new_script_item(source_path, &sid); + } + current->sc_sid = sid; current->sc_seq = -1; + current->sc_lnum = info->currentline; cleanup: xfree(info); -- cgit From 673d2b52fa4335aa083c52e6686f0728e25b8ebd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Mar 2023 16:04:57 +0100 Subject: refactor!: rename vim.pretty_print => vim.print Problem: The function name `vim.pretty_print`: 1. is verbose, which partially defeats its purpose as sugar 2. does not draw from existing precedent or any sort of convention (except external projects like penlight or python?), which reduces discoverability, and degrades signaling about best practices. Solution: - Rename to `vim.print`. - Change the behavior so that 1. strings are printed without quotes 2. each arg is printed on its own line 3. tables are indented with 2 instead of 4 spaces - Example: :lua ='a', 'b', 42, {a=3} a b 42 { a = 3 } Comparison of alternatives: - `vim.print`: - pro: consistent with Lua's `print()` - pro: aligns with potential `nvim_print` API function which will replace nvim_echo, nvim_notify, etc. - con: behaves differently than Lua's `print()`, slightly misleading? - `vim.echo`: - pro: `:echo` has similar "pretty print" behavior. - con: inconsistent with Lua idioms. - `vim.p`: - pro: very short, fits with `vim.o`, etc. - con: not as discoverable as "echo" - con: less opportunity for `local p = vim.p` because of potential shadowing. --- src/nvim/lua/executor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 11a02ea402..819e3cccff 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1623,12 +1623,12 @@ void ex_lua(exarg_T *const eap) } // When =expr is used transform it to print(vim.inspect(expr)) if (code[0] == '=') { - len += sizeof("vim.pretty_print()") - sizeof("="); + len += sizeof("vim.print()") - sizeof("="); // code_buf needs to be 1 char larger then len for null byte in the end. // lua nlua_typval_exec doesn't expect null terminated string so len // needs to end before null byte. char *code_buf = xmallocz(len); - vim_snprintf(code_buf, len + 1, "vim.pretty_print(%s)", code + 1); + vim_snprintf(code_buf, len + 1, "vim.print(%s)", code + 1); xfree(code); code = code_buf; } -- cgit From 07f59467da5a80c7ce46fdc9efcc0e2c18633df1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Mar 2023 20:09:56 +0800 Subject: refactor(completion): don't add and remove '^' for Lua (#22702) --- src/nvim/lua/executor.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 819e3cccff..3616f1f69f 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1857,12 +1857,6 @@ int nlua_expand_pat(expand_T *xp, char *pat, int *num_results, char ***results) lua_getfield(lstate, -1, "_expand_pat"); luaL_checktype(lstate, -1, LUA_TFUNCTION); - // ex expansion prepends a ^, but don't worry, it is not a regex - if (pat[0] != '^') { - return FAIL; - } - pat++; - // [ vim, vim._expand_pat, buf ] lua_pushlstring(lstate, (const char *)pat, strlen(pat)); -- cgit From a92b38934a2d00c13ee4d1969d994da15e0857ab Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 20 Mar 2023 21:11:10 +0100 Subject: feat(lua): allow `:=expr` as a shorter version of `:lua =expr` existing behavior of := and :[range]= are unchanged. `|` is still allowed with this usage. However, :=p and similar are changed in a way which could be construed as a breaking change. Allowing |ex-flags| for := in the first place was a mistake as any form of := DOES NOT MOVE THE CURSOR. So it would print one line number and then print a completely different line contents after that. --- src/nvim/lua/executor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 3616f1f69f..7e331a097f 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1621,14 +1621,15 @@ void ex_lua(exarg_T *const eap) xfree(code); return; } - // When =expr is used transform it to print(vim.inspect(expr)) - if (code[0] == '=') { - len += sizeof("vim.print()") - sizeof("="); + // When =expr is used transform it to vim.print(expr) + if (eap->cmdidx == CMD_equal || code[0] == '=') { + size_t off = (eap->cmdidx == CMD_equal) ? 0 : 1; + len += sizeof("vim.print()") - 1 - off; // code_buf needs to be 1 char larger then len for null byte in the end. // lua nlua_typval_exec doesn't expect null terminated string so len // needs to end before null byte. char *code_buf = xmallocz(len); - vim_snprintf(code_buf, len + 1, "vim.print(%s)", code + 1); + vim_snprintf(code_buf, len + 1, "vim.print(%s)", code + off); xfree(code); code = code_buf; } -- cgit From 3285cd6eccd9b7f33cc32f992c2607c3fc4ca13f Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 22 Mar 2023 10:09:28 +0000 Subject: refactor: do more in TRY_WRAP --- src/nvim/lua/executor.c | 35 ++++++++++++++++++----------------- src/nvim/lua/stdlib.c | 4 +--- 2 files changed, 19 insertions(+), 20 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 7e331a097f..dfbbfe9ab5 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1157,28 +1157,29 @@ int nlua_call(lua_State *lstate) } } - TRY_WRAP({ - // TODO(bfredl): this should be simplified in error handling refactor - force_abort = false; - suppress_errthrow = false; - did_throw = false; - did_emsg = false; - - try_start(); - typval_T rettv; - funcexe_T funcexe = FUNCEXE_INIT; - funcexe.fe_firstline = curwin->w_cursor.lnum; - funcexe.fe_lastline = curwin->w_cursor.lnum; - funcexe.fe_evaluate = true; + // TODO(bfredl): this should be simplified in error handling refactor + force_abort = false; + suppress_errthrow = false; + did_throw = false; + did_emsg = false; + + typval_T rettv; + funcexe_T funcexe = FUNCEXE_INIT; + funcexe.fe_firstline = curwin->w_cursor.lnum; + funcexe.fe_lastline = curwin->w_cursor.lnum; + funcexe.fe_evaluate = true; + + TRY_WRAP(&err, { // call_func() retval is deceptive, ignore it. Instead we set `msg_list` // (TRY_WRAP) to capture abort-causing non-exception errors. (void)call_func((char *)name, (int)name_len, &rettv, nargs, vim_args, &funcexe); - if (!try_end(&err)) { - nlua_push_typval(lstate, &rettv, false); - } - tv_clear(&rettv); }); + if (!ERROR_SET(&err)) { + nlua_push_typval(lstate, &rettv, false); + } + tv_clear(&rettv); + free_vim_args: while (i > 0) { tv_clear(&vim_args[--i]); diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 852e10c8d8..ee5676e927 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -287,10 +287,8 @@ int nlua_regex(lua_State *lstate) const char *text = luaL_checkstring(lstate, 1); regprog_T *prog = NULL; - TRY_WRAP({ - try_start(); + TRY_WRAP(&err, { prog = vim_regcomp((char *)text, RE_AUTO | RE_MAGIC | RE_STRICT); - try_end(&err); }); if (ERROR_SET(&err)) { -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/lua/executor.c | 2 +- src/nvim/lua/stdlib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index dfbbfe9ab5..b5dd7a3e78 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -623,7 +623,7 @@ static bool nlua_init_packages(lua_State *lstate, bool is_standalone) lua_getglobal(lstate, "require"); lua_pushstring(lstate, "vim._init_packages"); if (nlua_pcall(lstate, 1, 0)) { - os_errmsg((char *)lua_tostring(lstate, -1)); + os_errmsg(lua_tostring(lstate, -1)); os_errmsg("\n"); return false; } diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index ee5676e927..20a99b2836 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -288,7 +288,7 @@ int nlua_regex(lua_State *lstate) regprog_T *prog = NULL; TRY_WRAP(&err, { - prog = vim_regcomp((char *)text, RE_AUTO | RE_MAGIC | RE_STRICT); + prog = vim_regcomp(text, RE_AUTO | RE_MAGIC | RE_STRICT); }); if (ERROR_SET(&err)) { -- cgit From 090ade4af6344a7bc4ee56a8052c0739c0428c04 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 4 Apr 2023 12:58:16 +0100 Subject: refactor(treesitter): delegate region calculation to treesitter (#22576) --- src/nvim/lua/treesitter.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 289a0cb9b4..ae3a7b6d75 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -64,6 +64,7 @@ static struct luaL_Reg tree_meta[] = { { "__tostring", tree_tostring }, { "root", tree_root }, { "edit", tree_edit }, + { "included_ranges", tree_get_ranges }, { "copy", tree_copy }, { NULL, NULL } }; @@ -512,6 +513,24 @@ static int tree_edit(lua_State *L) return 0; } +static int tree_get_ranges(lua_State *L) +{ + TSTree **tree = tree_check(L, 1); + if (!(*tree)) { + return 0; + } + + bool include_bytes = (lua_gettop(L) >= 2) && lua_toboolean(L, 2); + + uint32_t len; + TSRange *ranges = ts_tree_included_ranges(*tree, &len); + + push_ranges(L, ranges, len, include_bytes); + + xfree(ranges); + return 1; +} + // Use the top of the stack (without popping it) to create a TSRange, it can be // either a lua table or a TSNode static void range_from_lua(lua_State *L, TSRange *range) -- cgit From 9e7426718b678e299f3fd03ef94f81b1e2d01ab0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 4 Apr 2023 23:59:39 +0100 Subject: feat(vim.diff): allow passing an integer for linematch --- src/nvim/lua/xdiff.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 9a7ae5c146..e0bbdb8942 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -32,7 +32,7 @@ typedef struct { Error *err; mmfile_t *ma; mmfile_t *mb; - bool linematch; + int64_t linematch; bool iwhite; } hunkpriv_t; @@ -128,7 +128,7 @@ static int hunk_locations_cb(long start_a, long count_a, long start_b, long coun { hunkpriv_t *priv = (hunkpriv_t *)cb_data; lua_State *lstate = priv->lstate; - if (priv->linematch) { + if (priv->linematch > 0 && count_a + count_b <= priv->linematch) { get_linematch_results(lstate, priv->ma, priv->mb, start_a, count_a, start_b, count_b, priv->iwhite); } else { @@ -208,7 +208,7 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char * } static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params, - bool *linematch, Error *err) + int64_t *linematch, Error *err) { const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err); @@ -265,8 +265,12 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, } cfg->interhunkctxlen = (long)v->data.integer; } else if (strequal("linematch", k.data)) { - *linematch = api_object_to_bool(*v, "linematch", false, err); - if (ERROR_SET(err)) { + if (v->type == kObjectTypeBoolean) { + *linematch = v->data.boolean ? INT64_MAX : 0; + } else if (v->type == kObjectTypeInteger) { + *linematch = v->data.integer; + } else { + api_set_error(err, kErrorTypeValidation, "linematch must be a boolean or integer"); goto exit_1; } } else { @@ -330,7 +334,7 @@ int nlua_xdl_diff(lua_State *lstate) xdemitconf_t cfg; xpparam_t params; xdemitcb_t ecb; - bool linematch = false; + int64_t linematch = 0; CLEAR_FIELD(cfg); CLEAR_FIELD(params); -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/lua/converter.c | 6 ++---- src/nvim/lua/executor.c | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index 6160b84485..9ff03bc67d 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -459,7 +459,7 @@ static bool typval_conv_special = false; TYPVAL_ENCODE_CONV_NUMBER(tv, flt) #define TYPVAL_ENCODE_CONV_STRING(tv, str, len) \ - lua_pushlstring(lstate, (const char *)(str), (len)) + lua_pushlstring(lstate, (str), (len)) #define TYPVAL_ENCODE_CONV_STR_STRING TYPVAL_ENCODE_CONV_STRING @@ -469,9 +469,7 @@ static bool typval_conv_special = false; #define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \ do { \ const blob_T *const blob_ = (blob); \ - lua_pushlstring(lstate, \ - blob_ != NULL ? (const char *)blob_->bv_ga.ga_data : "", \ - (size_t)(len)); \ + lua_pushlstring(lstate, blob_ != NULL ? blob_->bv_ga.ga_data : "", (size_t)(len)); \ } while (0) #define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \ diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index b5dd7a3e78..82db8445df 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1105,7 +1105,7 @@ static int nlua_debug(lua_State *lstate) tv_clear(&input); return 0; } - if (luaL_loadbuffer(lstate, (const char *)input.vval.v_string, + if (luaL_loadbuffer(lstate, input.vval.v_string, strlen(input.vval.v_string), "=(debug command)")) { nlua_error(lstate, _("E5115: Error while loading debug string: %.*s")); } else if (nlua_pcall(lstate, 0, 0)) { @@ -1652,7 +1652,7 @@ void ex_luado(exarg_T *const eap) emsg(_("cannot save undo information")); return; } - const char *const cmd = (const char *)eap->arg; + const char *const cmd = eap->arg; const size_t cmd_len = strlen(cmd); lua_State *const lstate = global_lstate; @@ -1693,7 +1693,7 @@ void ex_luado(exarg_T *const eap) break; } lua_pushvalue(lstate, -1); - const char *const old_line = (const char *)ml_get_buf(curbuf, l, false); + const char *const old_line = ml_get_buf(curbuf, l, false); // Get length of old_line here as calling Lua code may free it. const size_t old_line_len = strlen(old_line); lua_pushstring(lstate, old_line); @@ -1729,7 +1729,7 @@ void ex_luado(exarg_T *const eap) void ex_luafile(exarg_T *const eap) FUNC_ATTR_NONNULL_ALL { - nlua_exec_file((const char *)eap->arg); + nlua_exec_file(eap->arg); } /// Executes Lua code from a file or "-" (stdin). @@ -1860,7 +1860,7 @@ int nlua_expand_pat(expand_T *xp, char *pat, int *num_results, char ***results) luaL_checktype(lstate, -1, LUA_TFUNCTION); // [ vim, vim._expand_pat, buf ] - lua_pushlstring(lstate, (const char *)pat, strlen(pat)); + lua_pushlstring(lstate, pat, strlen(pat)); if (nlua_pcall(lstate, 1, 2) != 0) { nlua_error(lstate, @@ -2092,7 +2092,7 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) lua_setfield(lstate, -2, "line2"); lua_newtable(lstate); // f-args table - lua_pushstring(lstate, (const char *)eap->arg); + lua_pushstring(lstate, eap->arg); lua_pushvalue(lstate, -1); // Reference for potential use on f-args lua_setfield(lstate, -4, "args"); -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 82db8445df..3646fd876b 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1172,7 +1172,7 @@ int nlua_call(lua_State *lstate) TRY_WRAP(&err, { // call_func() retval is deceptive, ignore it. Instead we set `msg_list` // (TRY_WRAP) to capture abort-causing non-exception errors. - (void)call_func((char *)name, (int)name_len, &rettv, nargs, vim_args, &funcexe); + (void)call_func(name, (int)name_len, &rettv, nargs, vim_args, &funcexe); }); if (!ERROR_SET(&err)) { -- cgit From 706f871014b46300180156590ff269ee38473989 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 19 Apr 2023 17:04:00 +0100 Subject: build: update uncrustify to 0.76 --- src/nvim/lua/executor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 3646fd876b..13a0c4b0cd 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -377,7 +377,8 @@ static int nlua_schedule(lua_State *const lstate) // Dummy timer callback. Used by f_wait(). static void dummy_timer_due_cb(TimeWatcher *tw, void *data) -{} +{ +} // Dummy timer close callback. Used by f_wait(). static void dummy_timer_close_cb(TimeWatcher *tw, void *data) -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/lua/executor.c | 2 +- src/nvim/lua/spell.c | 6 +++--- src/nvim/lua/stdlib.c | 4 ++-- src/nvim/lua/treesitter.c | 2 +- src/nvim/lua/xdiff.c | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/lua') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 13a0c4b0cd..1c1f68b68d 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1094,7 +1094,7 @@ static int nlua_debug(lua_State *lstate) .v_type = VAR_UNKNOWN, }, }; - for (;;) { + while (true) { lua_settop(lstate, 0); typval_T input; get_user_input(input_args, &input, false, false); diff --git a/src/nvim/lua/spell.c b/src/nvim/lua/spell.c index 78e023c26d..742e8720f9 100644 --- a/src/nvim/lua/spell.c +++ b/src/nvim/lua/spell.c @@ -69,10 +69,10 @@ int nlua_spell_check(lua_State *lstate) lua_pushlstring(lst