aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/lua')
-rw-r--r--src/nvim/lua/api_wrappers.c30
-rw-r--r--src/nvim/lua/converter.c1
-rw-r--r--src/nvim/lua/executor.c10
-rw-r--r--src/nvim/lua/executor.h2
-rw-r--r--src/nvim/lua/secure.c2
-rw-r--r--src/nvim/lua/spell.c2
-rw-r--r--src/nvim/lua/stdlib.c51
-rw-r--r--src/nvim/lua/treesitter.c37
-rw-r--r--src/nvim/lua/xdiff.c1
9 files changed, 66 insertions, 70 deletions
diff --git a/src/nvim/lua/api_wrappers.c b/src/nvim/lua/api_wrappers.c
index 36847d1fc9..447ba846b4 100644
--- a/src/nvim/lua/api_wrappers.c
+++ b/src/nvim/lua/api_wrappers.c
@@ -1,19 +1,19 @@
-#include <lauxlib.h>
-#include <lua.h>
-#include <lualib.h>
+#include <lauxlib.h> // IWYU pragma: keep
+#include <lua.h> // IWYU pragma: keep
+#include <lualib.h> // IWYU pragma: keep
-#include "nvim/api/private/defs.h"
-#include "nvim/api/private/dispatch.h"
-#include "nvim/api/private/helpers.h"
-#include "nvim/errors.h"
-#include "nvim/ex_docmd.h"
-#include "nvim/ex_getln.h"
-#include "nvim/func_attr.h"
-#include "nvim/globals.h"
-#include "nvim/lua/converter.h"
-#include "nvim/lua/executor.h"
-#include "nvim/memory.h"
+#include "nvim/api/private/defs.h" // IWYU pragma: keep
+#include "nvim/api/private/dispatch.h" // IWYU pragma: keep
+#include "nvim/api/private/helpers.h" // IWYU pragma: keep
+#include "nvim/errors.h" // IWYU pragma: keep
+#include "nvim/ex_docmd.h" // IWYU pragma: keep
+#include "nvim/ex_getln.h" // IWYU pragma: keep
+#include "nvim/func_attr.h" // IWYU pragma: keep
+#include "nvim/globals.h" // IWYU pragma: keep
+#include "nvim/lua/converter.h" // IWYU pragma: keep
+#include "nvim/lua/executor.h" // IWYU pragma: keep
+#include "nvim/memory.h" // IWYU pragma: keep
#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "lua_api_c_bindings.generated.h"
+# include "lua_api_c_bindings.generated.h" // IWYU pragma: keep
#endif
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index 45ead154bc..292588ee64 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -22,6 +22,7 @@
#include "nvim/lua/executor.h"
#include "nvim/macros_defs.h"
#include "nvim/memory.h"
+#include "nvim/memory_defs.h"
#include "nvim/message.h"
#include "nvim/types_defs.h"
#include "nvim/vim_defs.h"
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index c4fa8b0fff..71c5cd4585 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -23,7 +23,6 @@
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/errors.h"
-#include "nvim/eval.h"
#include "nvim/eval/funcs.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/typval_defs.h"
@@ -47,10 +46,12 @@
#include "nvim/lua/treesitter.h"
#include "nvim/macros_defs.h"
#include "nvim/main.h"
+#include "nvim/mbyte_defs.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/memory_defs.h"
#include "nvim/message.h"
+#include "nvim/message_defs.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/option_vars.h"
#include "nvim/os/fileio.h"
@@ -275,10 +276,9 @@ static int nlua_luv_thread_common_cfpcall(lua_State *lstate, int nargs, int nres
#endif
}
const char *error = lua_tostring(lstate, -1);
-
loop_schedule_deferred(&main_loop,
event_create(nlua_luv_error_event,
- xstrdup(error),
+ error != NULL ? xstrdup(error) : NULL,
(void *)(intptr_t)(is_callback
? kThreadCallback
: kThread)));
@@ -957,7 +957,7 @@ static void nlua_print_event(void **argv)
HlMessage msg = KV_INITIAL_VALUE;
HlMessageChunk chunk = { { .data = argv[0], .size = (size_t)(intptr_t)argv[1] - 1 }, 0 };
kv_push(msg, chunk);
- msg_multihl(msg, "lua_print", true);
+ msg_multihl(msg, "lua_print", true, false);
}
/// Print as a Vim message
@@ -1587,8 +1587,8 @@ Object nlua_call_ref_ctx(bool fast, LuaRef ref, const char *name, Array args, Lu
if (nlua_fast_cfpcall(lstate, nargs, 1, -1) < 0) {
// error is already scheduled, set anyways to convey failure.
api_set_error(err, kErrorTypeException, "fast context failure");
+ return NIL;
}
- return NIL;
} else if (nlua_pcall(lstate, nargs, 1)) {
// if err is passed, the caller will deal with the error.
if (err) {
diff --git a/src/nvim/lua/executor.h b/src/nvim/lua/executor.h
index 32fde3853b..3a0c03412f 100644
--- a/src/nvim/lua/executor.h
+++ b/src/nvim/lua/executor.h
@@ -4,10 +4,10 @@
#include <lua.h>
#include <stdbool.h>
+#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep
#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
-#include "nvim/func_attr.h"
#include "nvim/macros_defs.h"
#include "nvim/types_defs.h"
#include "nvim/usercmd.h" // IWYU pragma: keep
diff --git a/src/nvim/lua/secure.c b/src/nvim/lua/secure.c
index 61277949c4..1560881b55 100644
--- a/src/nvim/lua/secure.c
+++ b/src/nvim/lua/secure.c
@@ -2,11 +2,11 @@
#include <stdbool.h>
#include <string.h>
+#include "nvim/ascii_defs.h"
#include "nvim/charset.h"
#include "nvim/errors.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/gettext_defs.h"
-#include "nvim/globals.h"
#include "nvim/lua/executor.h"
#include "nvim/lua/secure.h"
#include "nvim/memory.h"
diff --git a/src/nvim/lua/spell.c b/src/nvim/lua/spell.c
index f4dacd7a55..eec5892307 100644
--- a/src/nvim/lua/spell.c
+++ b/src/nvim/lua/spell.c
@@ -16,7 +16,7 @@
#include "nvim/spell.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "lua/spell.c.generated.h"
+# include "lua/spell.c.generated.h" // IWYU pragma: keep
#endif
int nlua_spell_check(lua_State *lstate)
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index e719d99640..2fc9367ead 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -18,11 +18,13 @@
#include "nvim/api/private/helpers.h"
#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
+#include "nvim/autocmd_defs.h"
#include "nvim/buffer_defs.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/typval_defs.h"
#include "nvim/eval/vars.h"
#include "nvim/eval/window.h"
+#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/fold.h"
@@ -619,41 +621,36 @@ static int nlua_with(lua_State *L)
int rets = 0;
cmdmod_T save_cmdmod = cmdmod;
+ CLEAR_FIELD(cmdmod);
cmdmod.cmod_flags = flags;
apply_cmdmod(&cmdmod);
- if (buf || win) {
- try_start();
- }
-
- aco_save_T aco;
- win_execute_T win_execute_args;
Error err = ERROR_INIT;
+ TRY_WRAP(&err, {
+ aco_save_T aco;
+ win_execute_T win_execute_args;
- if (win) {
- tabpage_T *tabpage = win_find_tabpage(win);
- if (!win_execute_before(&win_execute_args, win, tabpage)) {
- goto end;
+ if (win) {
+ tabpage_T *tabpage = win_find_tabpage(win);
+ if (!win_execute_before(&win_execute_args, win, tabpage)) {
+ goto end;
+ }
+ } else if (buf) {
+ aucmd_prepbuf(&aco, buf);
}
- } else if (buf) {
- aucmd_prepbuf(&aco, buf);
- }
- int s = lua_gettop(L);
- lua_pushvalue(L, 2);
- status = lua_pcall(L, 0, LUA_MULTRET, 0);
- rets = lua_gettop(L) - s;
+ int s = lua_gettop(L);
+ lua_pushvalue(L, 2);
+ status = lua_pcall(L, 0, LUA_MULTRET, 0);
+ rets = lua_gettop(L) - s;
- if (win) {
- win_execute_after(&win_execute_args);
- } else if (buf) {
- aucmd_restbuf(&aco);
- }
-
-end:
- if (buf || win) {
- try_end(&err);
- }
+ if (win) {
+ win_execute_after(&win_execute_args);
+ } else if (buf) {
+ aucmd_restbuf(&aco);
+ }
+ end:;
+ });
undo_cmdmod(&cmdmod);
cmdmod = save_cmdmod;
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index c80e7b7672..3e33fcd142 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -17,10 +17,12 @@
#ifdef HAVE_WASMTIME
# include <wasm.h>
+
+# include "nvim/os/fs.h"
#endif
-#include "klib/kvec.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/ascii_defs.h"
#include "nvim/buffer_defs.h"
#include "nvim/globals.h"
#include "nvim/lua/treesitter.h"
@@ -28,7 +30,6 @@
#include "nvim/map_defs.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
-#include "nvim/os/fs.h"
#include "nvim/pos_defs.h"
#include "nvim/strings.h"
#include "nvim/types_defs.h"
@@ -127,9 +128,9 @@ static const TSLanguage *load_language_from_object(lua_State *L, const char *pat
{
uv_lib_t lib;
if (uv_dlopen(path, &lib)) {
+ xstrlcpy(IObuff, uv_dlerror(&lib), sizeof(IObuff));
uv_dlclose(&lib);
- luaL_error(L, "Failed to load parser for language '%s': uv_dlopen: %s",
- lang_name, uv_dlerror(&lib));
+ luaL_error(L, "Failed to load parser for language '%s': uv_dlopen: %s", lang_name, IObuff);
}
char symbol_buf[128];
@@ -137,8 +138,9 @@ static const TSLanguage *load_language_from_object(lua_State *L, const char *pat
TSLanguage *(*lang_parser)(void);
if (uv_dlsym(&lib, symbol_buf, (void **)&lang_parser)) {
+ xstrlcpy(IObuff, uv_dlerror(&lib), sizeof(IObuff));
uv_dlclose(&lib);
- luaL_error(L, "Failed to load parser: uv_dlsym: %s", uv_dlerror(&lib));
+ luaL_error(L, "Failed to load parser: uv_dlsym: %s", IObuff);
}
TSLanguage *lang = lang_parser();
@@ -216,7 +218,7 @@ static int add_language(lua_State *L, bool is_wasm)
? load_language_from_wasm(L, path, lang_name)
: load_language_from_object(L, path, lang_name, symbol_name);
- uint32_t lang_version = ts_language_version(lang);
+ uint32_t lang_version = ts_language_abi_version(lang);
if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
|| lang_version > TREE_SITTER_LANGUAGE_VERSION) {
return luaL_error(L,
@@ -298,7 +300,7 @@ int tslua_inspect_lang(lua_State *L)
lua_pushboolean(L, ts_language_is_wasm(lang));
lua_setfield(L, -2, "_wasm");
- lua_pushinteger(L, ts_language_version(lang)); // [retval, version]
+ lua_pushinteger(L, ts_language_abi_version(lang)); // [retval, version]
lua_setfield(L, -2, "_abi_version");
return 1;
@@ -474,7 +476,7 @@ static int parser_parse(lua_State *L)
#undef BUFSIZE
}
- input = (TSInput){ (void *)buf, input_cb, TSInputEncodingUTF8 };
+ input = (TSInput){ (void *)buf, input_cb, TSInputEncodingUTF8, NULL };
new_tree = ts_parser_parse(p, old_tree, input);
break;
@@ -488,13 +490,18 @@ 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.
// 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]
@@ -831,7 +838,6 @@ static struct luaL_Reg node_meta[] = {
{ "named_descendant_for_range", node_named_descendant_for_range },
{ "parent", node_parent },
{ "__has_ancestor", __has_ancestor },
- { "child_containing_descendant", node_child_containing_descendant },
{ "child_with_descendant", node_child_with_descendant },
{ "iter_children", node_iter_children },
{ "next_sibling", node_next_sibling },
@@ -1175,15 +1181,6 @@ static int __has_ancestor(lua_State *L)
return 1;
}
-static int node_child_containing_descendant(lua_State *L)
-{
- TSNode node = node_check(L, 1);
- TSNode descendant = node_check(L, 2);
- TSNode child = ts_node_child_containing_descendant(node, descendant);
- push_node(L, child, 1);
- return 1;
-}
-
static int node_child_with_descendant(lua_State *L)
{
TSNode node = node_check(L, 1);
diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c
index b9f96abf73..f51c1a05cd 100644
--- a/src/nvim/lua/xdiff.c
+++ b/src/nvim/lua/xdiff.c
@@ -1,4 +1,5 @@
#include <lauxlib.h>
+#include <limits.h>
#include <lua.h>
#include <stdbool.h>
#include <stdint.h>