aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/executor.c
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2025-06-02 06:03:35 +0800
committerGitHub <noreply@github.com>2025-06-01 15:03:35 -0700
commit5cfbc35aa8381f3e199be248fbb94b05c16f82ff (patch)
tree3c000e09611e0b4fd1e37574904343a46a38df88 /src/nvim/lua/executor.c
parent80753332d1fe8035b54d1bd8936e222801620c36 (diff)
downloadrneovim-5cfbc35aa8381f3e199be248fbb94b05c16f82ff.tar.gz
rneovim-5cfbc35aa8381f3e199be248fbb94b05c16f82ff.tar.bz2
rneovim-5cfbc35aa8381f3e199be248fbb94b05c16f82ff.zip
fix(api): add missing nargs field to user command Lua callbacks #34210
Problem: nvim_create_user_command() Lua callbacks were missing the documented nargs field in the options table passed to the callback function. Solution: Add nargs field derivation from command argument type flags in nlua_do_ucmd(), using the same logic as nvim_parse_cmd().
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r--src/nvim/lua/executor.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index fc11d2b966..2f5c7566f4 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -2206,6 +2206,26 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview)
}
lua_setfield(lstate, -2, "count");
+ char nargs[2];
+ if (cmd->uc_argt & EX_EXTRA) {
+ if (cmd->uc_argt & EX_NOSPC) {
+ if (cmd->uc_argt & EX_NEEDARG) {
+ nargs[0] = '1';
+ } else {
+ nargs[0] = '?';
+ }
+ } else if (cmd->uc_argt & EX_NEEDARG) {
+ nargs[0] = '+';
+ } else {
+ nargs[0] = '*';
+ }
+ } else {
+ nargs[0] = '0';
+ }
+ nargs[1] = NUL;
+ lua_pushstring(lstate, nargs);
+ lua_setfield(lstate, -2, "nargs");
+
// The size of this buffer is chosen empirically to be large enough to hold
// every possible modifier (with room to spare). If the list of possible
// modifiers grows this may need to be updated.