diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-06-27 14:10:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-27 14:10:13 +0800 |
commit | cf23695dd748281daaf68e69ac48bf9eb27f2425 (patch) | |
tree | 7f92fadadcec13599a0da4997adf3f16a9a5068e | |
parent | e2f9d0332b673431d79f0db9386956055674006b (diff) | |
download | rneovim-cf23695dd748281daaf68e69ac48bf9eb27f2425.tar.gz rneovim-cf23695dd748281daaf68e69ac48bf9eb27f2425.tar.bz2 rneovim-cf23695dd748281daaf68e69ac48bf9eb27f2425.zip |
fix(api): nvim_parse_cmd check for ambiguous user command (#19116)
-rw-r--r-- | src/nvim/ex_docmd.c | 19 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 3 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 671e83def6..00aadc2af5 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -82,8 +82,13 @@ #include "nvim/vim.h" #include "nvim/window.h" -static char *e_no_such_user_defined_command_str = N_("E184: No such user-defined command: %s"); -static char *e_no_such_user_defined_command_in_current_buffer_str +static char e_no_such_user_defined_command_str[] + = N_("E184: No such user-defined command: %s"); +static char e_ambiguous_use_of_user_defined_command[] + = N_("E464: Ambiguous use of user-defined command"); +static char e_not_an_editor_command[] + = N_("E492: Not an editor command"); +static char e_no_such_user_defined_command_in_current_buffer_str[] = N_("E1237: No such user-defined command in current buffer: %s"); static int quitmore = 0; @@ -1439,6 +1444,10 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er eap->cmd = skipwhite(eap->cmd + 1); } p = find_ex_command(eap, NULL); + if (p == NULL) { + *errormsg = _(e_ambiguous_use_of_user_defined_command); + return false; + } // Set command address type and parse command range set_cmd_addr_type(eap, (char_u *)p); @@ -1455,7 +1464,7 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er } // Fail if command is invalid if (eap->cmdidx == CMD_SIZE) { - STRCPY(IObuff, _("E492: Not an editor command")); + STRCPY(IObuff, _(e_not_an_editor_command)); // If the modifier was parsed OK the error must be in the following command char *cmdname = after_modifier ? after_modifier : cmdline; append_command(cmdname); @@ -1886,14 +1895,14 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter if (p == NULL) { if (!ea.skip) { - errormsg = _("E464: Ambiguous use of user-defined command"); + errormsg = _(e_ambiguous_use_of_user_defined_command); } goto doend; } // Check for wrong commands. if (ea.cmdidx == CMD_SIZE) { if (!ea.skip) { - STRCPY(IObuff, _("E492: Not an editor command")); + STRCPY(IObuff, _(e_not_an_editor_command)); // If the modifier was parsed OK the error must be in the following // command char *cmdname = after_modifier ? after_modifier : *cmdlinep; diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ef6798dea3..c05345dd4c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3520,6 +3520,9 @@ describe('API', function() pcall_err(meths.parse_cmd, 'Fubar!', {})) eq('Error while parsing command line: E481: No range allowed', pcall_err(meths.parse_cmd, '4,6Fubar', {})) + command('command! Foobar echo foo') + eq('Error while parsing command line: E464: Ambiguous use of user-defined command', + pcall_err(meths.parse_cmd, 'F', {})) end) end) describe('nvim_cmd', function() |