diff options
author | Javier Lopez <graulopezjavier@gmail.com> | 2022-08-21 08:19:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-21 15:19:29 +0200 |
commit | dde90f0ca4e394667afe39c18f4a4dabdd8a6666 (patch) | |
tree | 47a8e51fe02f013c15157cb87ae18bcdb15c5141 /src/nvim/lua/executor.c | |
parent | 5928d5c2f11754e1d2cc383a1568c3664a38207d (diff) | |
download | rneovim-dde90f0ca4e394667afe39c18f4a4dabdd8a6666.tar.gz rneovim-dde90f0ca4e394667afe39c18f4a4dabdd8a6666.tar.bz2 rneovim-dde90f0ca4e394667afe39c18f4a4dabdd8a6666.zip |
fix(api/command): fargs behavior when no arguments are passed (#19862)
Problem: A command defined with `nargs="?"` returns `fargs={""}` to
a Lua callback when executed with no arguments, which is inconsistent
with how`nargs="*"` behaves.
Solution: Pass `fargs={}` for no argument with `nargs="?"` as well.
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 38c19ed456..d1d1480696 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1940,8 +1940,13 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) // Split args by unescaped whitespace |<f-args>| (nargs dependent) if (cmd->uc_argt & EX_NOSPC) { - // Commands where nargs = 1 or "?" fargs is the same as args - lua_rawseti(lstate, -2, 1); + if ((cmd->uc_argt & EX_NEEDARG) || STRLEN(eap->arg)) { + // For commands where nargs is 1 or "?" and argument is passed, fargs = { args } + lua_rawseti(lstate, -2, 1); + } else { + // if nargs = "?" and no argument is passed, fargs = {} + lua_pop(lstate, 1); // Pop the reference of opts.args + } } else if (eap->args == NULL) { // For commands with more than one possible argument, split if argument list isn't available. lua_pop(lstate, 1); // Pop the reference of opts.args |