summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/api/command_spec.lua
AgeCommit message (Collapse)AuthorFiles
2026-04-24fix(api): leak preview callback LuaRef in nvim_create_user_command #39357Barrett Ruth1
Problem: Invalid `nvim_create_user_command` calls can leak the `preview` callback reference after Neovim has taken ownership of it. 1. build with {a,l}san 2. run: ```sh <path/to/nvim> --headless -u NONE --clean +'lua for i = 1, 100 do pcall(vim.api.nvim_create_user_command, "some very epic stuff" .. i, {}, -- NOTE: this is INVALID (not a function or string) { preview = function() end }) end vim.cmd("qa!") ' +qa ``` 3. see: ``` 100 lua references were leaked! ``` Solution: Clear `preview_luaref` in `err:`.
2025-12-06docs: miscJustin M. Keyes1
fix https://github.com/neovim/neovim.github.io/issues/419 Co-authored-by: Rob Pilling <robpilling@gmail.com>
2025-11-25feat(api): nvim_get_commands returns function fields #36415Rob Pilling1
Problem: nvim_get_commands does not return callbacks defined for "preview", "complete", or the command itself. Solution: - Return Lua function as "callback" field in a Lua context. - Return "preview" function in a Lua context. - BREAKING: Return "complete" as a function instead of a boolean.
2025-08-02fix(api): nvim_create_user_command addr option should allow ranges #35077glepnir1
Problem: Using `addr` without `range` in nvim_create_user_command gives "No range allowed" error, inconsistent with `:command -addr` behavior. Solution: Set EX_RANGE flag when `addr` option is specified to match `:command` behavior.
2025-06-01fix(api): add missing nargs field to user command Lua callbacks #34210glepnir1
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().
2025-05-04feat(messages): cleanup Lua error messagesJustin M. Keyes1
"Error" in error messages is redundant. Just provide the context, don't say "Error ...".
2025-04-14fix(completion): avoid freeing uninitialized value (#33459)zeertzjq1
2025-01-08fix(api): crash on invalid buffer to nvim_buf_del_user_command (#31908)zeertzjq1
2024-04-23test: improve test conventionsdundargoc1
Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
2024-04-10refactor(test): inject after_each differentlyLewis Russell1
2024-04-08test: improve test conventionsdundargoc1
Work on https://github.com/neovim/neovim/issues/27004.
2024-01-12test: rename (meths, funcs) -> (api, fn)Lewis Russell1
2024-01-12test: normalise nvim bridge functionsLewis Russell1
- remove helpers.cur*meths - remove helpers.nvim
2024-01-12test: typing for helpers.methsLewis Russell1
2024-01-12test: do not inject vim module into global helpersLewis Russell1
2024-01-03refactor: format test/*Justin M. Keyes1
2023-02-16fix(api): allow empty Lua table for nested dicts #22268Justin M. Keyes1
Problem: The Lua-API bridge allows Dict params to be empty Lua (list) tables at the function-signature level. But not for _nested_ Dicts, because they are not modeled: https://github.com/neovim/neovim/blob/fae754073289566051433fae74ec65783f9e7a6a/src/nvim/api/keysets.lua#L184 Some API functions like nvim_cmd check for kObjectTypeDictionary and don't handle the case of empty Lua tables (treated as "Array"). Solution: Introduce VALIDATE_T_DICT and use it in places where kObjectTypeDictionary was being checked directly. fixes #21005
2023-02-14refactor(api): consistent VALIDATE messages #22262Justin M. Keyes1
Problem: Validation messages are not consistently formatted. - Parameter names sometimes are NOT quoted. - Descriptive names (non-parameters) sometimes ARE quoted. Solution: Always quote the `name` value passed to a VALIDATE macro _unless_ the value has whitespace.
2023-02-14refactor(api): VALIDATE macros #22187Justin M. Keyes1
Problem: - API validation involves too much boilerplate. - API validation errors are not consistently worded. Solution: Introduce some macros. Currently these are clumsy, but they at least help with consistency and avoid some nesting.
2022-11-07feat(api): add command name to Lua command callback optsFamiu Haque1
Adds a `name` key to the opts dict passed to Lua command callbacks created using `nvim_create_user_command()`. This is useful for when multiple commands use the same callback. Note that this kind of behavior is not as strange as one might think, even some internal Neovim commands reuse the same internal C function, differing their behavior by checking the command name. `substitute`, `smagic` and `snomagic` are examples of that. This will also be useful for generalized Lua command preview functions that can preview a wide range of commands, in which case knowing the command name is necessary for the preview function to actually be able to execute the command that it's supposed to preview.
2022-09-28fix(lua): fix architecture-dependent behavior in usercmd "reg" (#20384)zeertzjq1
I don't think using an integer as a NUL-terminated string can work on big-endian systems, at least. This is also not tested. Add a test. Also fix a mistake in the docs of nvim_parse_cmd.
2022-09-02fix(api)!: correctly deal with number before :tabzeertzjq1
Now nvim_parse_cmd and nvim_create_user_command use a "tab" value which is the same as the number passed before :tab modifier instead of the number plus 1, and "tab" value is -1 if :tab modifier is not used.
2022-09-01feat(api): add support for :horizontal modifierzeertzjq1
2022-08-25fix(usercmd): also check for whitespace after escaped character (#19942)zeertzjq1
2022-08-21fix(api/command): fargs behavior when no arguments are passed (#19862)Javier Lopez1
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.
2022-07-03feat(api): add `unsilent` to command APIszeertzjq1
2022-06-08fix(nvim_create_user_command): make `smods` work with `nvim_cmd`Famiu Haque1
Closes #18876.
2022-05-31feat: add preview functionality to user commandsFamiu Haque1
Adds a Lua-only `preview` flag to user commands which allows the command to be incrementally previewed like `:substitute` when 'inccommand' is set.
2022-05-29feat(nvim_create_user_command): pass structured modifiers to commandsFamiu Haque1
Adds an `smods` key to `nvim_create_user_command` Lua command callbacks, which has command modifiers but in a structured format. This removes the need to manually parse command modifiers. It also reduces friction in using `nvim_cmd` inside a Lua command callback.
2022-04-13fix(api): correctly pass f-args for nvim_create_user_command (#18098)Gregory Anders1
Skip runs of whitespace and do not include `\` characters when followed by another `\` or whitespace. This matches the behavior of <f-args> when used with `:command`.
2022-04-10refactor!: rename nvim_add_user_command to nvim_create_user_commandGregory Anders1
2022-03-27feat(test): use nvim_exec in helpers.source() #16064Justin M. Keyes1
helpers.source() was a hack to work around the lack of anonymous :source. Its "create tempfile" behavior is not a required part of most tests that use it. Some tests still need the old "create tempfile" behavior either because they test SID behavior, or because of missing nvim_exec features: #16071
2022-02-27feat(lua): add <f-args> to user commands callback (#17522)Javier Lopez1
Works similar to ex <f-args>. It only splits the arguments if the command has more than one posible argument. In cases were the command can only have 1 argument opts.fargs = { opts.args }
2022-02-15fix(api): validate command names in nvim_add_user_command (#17406)Gregory Anders1
This uses the same validation used when defining commands with `:command`.
2022-01-21vim-patch:8.2.3584: "verbose set efm" reports location of the :compiler commandzeertzjq1
Problem: "verbose set efm" reports the location of the :compiler command. (Gary Johnson) Solution: Add the "-keepscript" argument to :command and use it when defining CompilerSet. https://github.com/vim/vim/commit/58ef8a31d7087d495ab1582be5b7a22796ac2451
2021-12-28feat(api): implement nvim_{add,del}_user_commandGregory Anders1
Add support for adding and removing custom user commands with the Nvim API.
2021-10-03refactor(api): handle option dicts properlyBjörn Linse1
Do not copy a lot of lua strings (dict keys) to just strequal() them Just compare them directly to a dedicated hash function. feat(generators): HASHY McHASHFACE
2021-08-08vim-patch:8.2.3141: no error when using :complete for :command without -nargsJan Edmund Lazo1
Problem: No error when using :complete for :command without -nargs. Solution: Give an error. (Martin Tournoij, closes vim/vim#8544, closes vim/vim#8541) https://github.com/vim/vim/commit/de69a7353e9bec552e15dbe3706a9f4e88080fce N/A patches for version.c: vim-patch:8.1.1801: cannot build without the +eval feature Problem: Cannot build without the +eval feature. Solution: Always define funcexe_T. https://github.com/vim/vim/commit/505e43a20eb25674b18d73971fe3b51dad917f9a vim-patch:8.1.1818: unused variable Problem: Unused variable. Solution: Remove the variable. (Mike Williams) https://github.com/vim/vim/commit/b4a88a0441a65a0c9411c294825a08ca703f541e vim-patch:8.2.1464: Vim9: build warning for unused variable Problem: Vim9: build warning for unused variable. Solution: Delete the variable declaration. https://github.com/vim/vim/commit/829ac868b7615d73dbfb536f7fcd44fc7c5b7c1d vim-patch:8.2.2639: build failure when fsync() is not available Problem: Build failure when fsync() is not available. Solution: Add #ifdef. https://github.com/vim/vim/commit/5ea79a2599d35f75e1ae8a75d2711c754c4cb7c4 vim-patch:8.2.2814: Vim9: unused variable Problem: Vim9: unused variable. (John Marriott) Solution: Adjust #ifdef. https://github.com/vim/vim/commit/b06b50dfa06e1cbefd634e2735e7cd5ddd5b911c vim-patch:8.2.2947: build failure without the channel feature Problem: Build failure without the channel feature. Solution: Add back #ifdef. (John Marriott) https://github.com/vim/vim/commit/f5bfa8faa7bbe025c10148d37e8b47217a430a3b vim-patch:8.2.2976: build failure without the +eval feature Problem: Build failure without the +eval feature. Solution: Add #ifdefs. https://github.com/vim/vim/commit/8de901e1f1b051e02a61ae76ad7c925e4c0642e5 vim-patch:8.2.2986: build failure without the profile feature Problem: Build failure without the profile feature. Solution: Add #ifdef. https://github.com/vim/vim/commit/d9f31c13d217b4b97f724774a67a6d1f8640e8ae vim-patch:8.2.3114: Amiga-like systems: build error using stat() Problem: Amiga-like systems: build error using stat(). Solution: Only build swapfile_process_running() on systems where it is actually used. (Ola Söder, closes vim/vim#8519) https://github.com/vim/vim/commit/599a6e5b3629d943a795cd69e4d3d19886f86405
2019-09-06test: Eliminate expect_errJustin M. Keyes1
Eliminate `expect_err` in favor of `pcall_err` + `eq` or `matches`.
2018-07-12tests: <SNR> is represented as 'R' (ASCII)Jan Edmund Lazo1
2018-05-12API: nvim_get_commands(): return DictionaryJustin M. Keyes1
2018-05-12API: nvim_get_commands(): builtin is irrelevant for buffer-localJustin M. Keyes1
builtin commands are never buffer-local, so we can return empty for that case.
2018-05-11API: nvim_get_commands(): more attributesJustin M. Keyes1
Support more :command attributes: -bang -bar -register
2018-05-11API: nvim_get_commands(): always return keysJustin M. Keyes1
- Always return all keys, with at least NIL value. - Require `opts` param to be {"builtin":false} - Validate `opts` param
2018-05-11API: nvim_get_commands()Nimit Bhardwaj1