From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/lua/stdlib.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 33770b2e62..d7a7abe3c8 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -22,7 +22,6 @@ #include "nvim/eval/vars.h" #include "nvim/ex_eval.h" #include "nvim/fold.h" -#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/lua/base64.h" #include "nvim/lua/converter.h" -- cgit From 040369e1e4b86c4655a6885b36ee89ad4f10ca16 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Mon, 4 Dec 2023 11:37:45 +0900 Subject: fix(treesitter): don't forcefully open folds Problem: When `vim._foldupdate()` is invoked inside a scheduled callback, the cursor may have moved to a line with a closed fold, e.g., after `dd` on the line that is one line above a folded region. Then it opens the fold, which is unnecessary and distracting. Legacy foldexprs do not have this issue. Solution: Don't explicitly open folds on cursor. Note: This doesn't completely prevent spurious opening of folds. That is due to bugs in treesitter foldexpr algorithm, which should be addressed separately. --- src/nvim/lua/stdlib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index d7a7abe3c8..fc2fedeaa1 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -536,11 +536,14 @@ static int nlua_iconv(lua_State *lstate) return 1; } -// Like 'zx' but don't call newFoldLevel() +// Update foldlevels (e.g., by evaluating 'foldexpr') for all lines in the current window without +// invoking other side effects. Unlike `zx`, it does not close manually opened folds and does not +// open folds under the cursor. static int nlua_foldupdate(lua_State *lstate) { curwin->w_foldinvalid = true; // recompute folds - foldOpenCursor(); + foldUpdate(curwin, 1, (linenr_T)MAXLNUM); + curwin->w_foldinvalid = false; return 0; } -- cgit From 6cb78e2d1c4c6c63c628c965076a07ce5f7adbb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 16 Dec 2023 22:14:28 +0100 Subject: docs: add style rule regarding initialization Specifically, specify that each initialization should be done on a separate line. --- src/nvim/lua/stdlib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index fc2fedeaa1..4b7d2dab21 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -82,7 +82,8 @@ static int regex_match_line(lua_State *lstate) handle_T bufnr = (handle_T)luaL_checkinteger(lstate, 2); linenr_T rownr = (linenr_T)luaL_checkinteger(lstate, 3); - int start = 0, end = -1; + int start = 0; + int end = -1; if (narg >= 4) { start = (int)luaL_checkinteger(lstate, 4); } @@ -177,7 +178,8 @@ int nlua_str_utfindex(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL } } - size_t codepoints = 0, codeunits = 0; + size_t codepoints = 0; + size_t codeunits = 0; mb_utflen(s1, (size_t)idx, &codepoints, &codeunits); lua_pushinteger(lstate, (lua_Integer)codepoints); -- cgit From af93a74a0f4afa9a3a4f55ffdf28141eaf776d22 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 18 Dec 2023 10:55:23 +0100 Subject: refactor: run IWYU on entire repo Reference: https://github.com/neovim/neovim/issues/6371. --- src/nvim/lua/stdlib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 4b7d2dab21..db710457c3 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #ifdef NVIM_VENDOR_BIT # include "bit.h" @@ -14,7 +14,6 @@ #include "cjson/lua_cjson.h" #include "mpack/lmpack.h" -#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" -- cgit From 1813661a6197c76ea6621284570aca1d56597099 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 4 Jan 2024 15:38:16 +0100 Subject: refactor(IWYU): fix headers Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want. --- src/nvim/lua/stdlib.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index db710457c3..5fea1ba5d8 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -14,10 +14,12 @@ #include "cjson/lua_cjson.h" #include "mpack/lmpack.h" +#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii_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/ex_eval.h" #include "nvim/fold.h" @@ -29,10 +31,12 @@ #include "nvim/lua/xdiff.h" #include "nvim/map_defs.h" #include "nvim/mbyte.h" +#include "nvim/mbyte_defs.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/pos_defs.h" #include "nvim/regexp.h" +#include "nvim/regexp_defs.h" #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/types_defs.h" -- cgit From ad5a155b1f4b387d3aaa54c91d0146cb0287bb9f Mon Sep 17 00:00:00 2001 From: VanaIgr Date: Mon, 26 Feb 2024 04:12:55 -0600 Subject: fix(mbyte): fix bugs in utf_cp_*_off() functions Problems: - Illegal bytes after valid UTF-8 char cause utf_cp_*_off() to fail. - When stream isn't NUL-terminated, utf_cp_*_off() may go over the end. Solution: Don't go over end of the char of end of the string. --- src/nvim/lua/stdlib.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/nvim/lua/stdlib.c') diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 5fea1ba5d8..8f58fd1a1a 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -226,11 +226,12 @@ 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); ptrdiff_t offset = luaL_checkinteger(lstate, 2); - if (offset < 0 || offset > (intptr_t)s1_len) { + if (offset <= 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } - int head_offset = -utf_cp_head_off(s1, s1 + offset - 1); - lua_pushinteger(lstate, head_offset); + size_t const off = (size_t)(offset - 1); + int head_off = -utf_cp_bounds_len(s1, s1 + off, (int)(s1_len - off)).begin_off; + lua_pushinteger(lstate, head_off); return 1; } @@ -246,11 +247,12 @@ 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); ptrdiff_t offset = luaL_checkinteger(lstate, 2); - if (offset < 0 || offset > (intptr_t)s1_len) { + if (offset <= 0 || offset > (intptr_t)s1_len) { return luaL_error(lstate, "index out of range"); } - int tail_offset = utf_cp_tail_off(s1, s1 + offset - 1); - lua_pushinteger(lstate, tail_offset); + size_t const off = (size_t)(offset - 1); + int tail_off = utf_cp_bounds_len(s1, s1 + off, (int)(s1_len - off)).end_off - 1; + lua_pushinteger(lstate, tail_off); return 1; } -- cgit