Skip to content

breaking: Rework CreateCommandOpts, CommandInfos and CommandComplete#296

Open
c-c-k wants to merge 1 commit into
noib3:mainfrom
c-c-k:stack/025-pr-fix-user-command-completion-on-v0.12.0
Open

breaking: Rework CreateCommandOpts, CommandInfos and CommandComplete#296
c-c-k wants to merge 1 commit into
noib3:mainfrom
c-c-k:stack/025-pr-fix-user-command-completion-on-v0.12.0

Conversation

@c-c-k

@c-c-k c-c-k commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

PR change list

  • Add custom serde deserializer for CommandComplete.
  • Rename CommandComplete::CustomList(fun) to CommandComplete::Callback(fun).
  • Add CommandComplete::Custom(String).
  • Add CommandComplete::Customlist(String).
  • Add other CommandComplete variants listed in the NVIM documentation.
  • Add CommandComplete tests.
  • Change CommandInfos::complete's type from String to CommandComplete.
  • Mark nvim_oxi::api::get_commands as unsafe.
  • Modify CreateCommandOpts::complete to accept a function directly.
  • Modify existing create_user_command tests to get_commands being unsafe.

Rationale

This PR was originally necessary to fix the failing create_del_user_command and user_command_with_count tests because NVIM v0.12 modified a few of the builtin plugin commands to define the complete field directly as a Lua function instead of as a "customlist" with a complete_arg="v:lua..." field.

In the process of working on this PR however I realized that the C API nvim_get_commands function creates a Lua registry slot for each command and completion callback, which it expects the caller to clean up.
Currently nvim-oxi does not perform this cleanup.
Consequentially calling nvim_oxi::api::get_commands creates a serious leak of Lua registry slots which in turn also prevents the callbacks from being garbage collected if their commands are deleted.

Fixing this will probably require reworking nvim_oxi::Function into freeing the Lua registry slot it contains a reference to when dropped.
This in turn will require adjusting the behavior of all the nvim_oxi functions that use Function, which is beyond the scope of this PR.
However, since the above solution will require converting all the raw lua_refs returned by nvim_get_commands into Function's it would be necessary to process the entire Dictionary returned by the C API function before returning it to the user.
In which case I think it also makes sense to change the return type of nvim_get_commands from impl SuperIterator<CommandInfos> to HashMap<String, CommandInfos> which would also fall in line with the return type of the corresponding functions in the C and Lua API's.

edit: After some AI consultation I realize a better solution would probably be to create a custom iterator that would do minimal cleanup processing for any remaining items in the iterator when it's dropped.

Regardless of the above, I think it would be appropriate to rename CommandComplete::CustomList to CommandComplete::Callback so as to use CommandComplete::Customlist for it's official purpose of holding the name of a Vim Script function.

Also I think it would be convenient to allow CreateCommandOpts::complete to accept a function directly (but still to also accept CommandComplete).

@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from bb19716 to 7b96ca2 Compare April 4, 2026 09:26
@c-c-k c-c-k marked this pull request as ready for review April 4, 2026 09:28
@c-c-k c-c-k changed the title Stack/025: fix user command completion on v0.12.0 fix: user command completion on v0.12.0 Apr 5, 2026
@c-c-k

c-c-k commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Will drop the v0.10 flags, sec

@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from 7b96ca2 to 059baf6 Compare April 6, 2026 10:22
@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from 059baf6 to 6c884f0 Compare April 22, 2026 16:04
@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from 6c884f0 to ca69ed4 Compare May 24, 2026 14:26
@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch 2 times, most recently from 5b28554 to a57f318 Compare June 15, 2026 15:45
@c-c-k c-c-k marked this pull request as draft June 17, 2026 17:15
@c-c-k c-c-k closed this Jun 17, 2026
@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from a57f318 to 7ad27a7 Compare June 17, 2026 17:50
@c-c-k c-c-k reopened this Jun 17, 2026
@c-c-k c-c-k changed the title fix: user command completion on v0.12.0 update CreateCommandOpts, CommandInfos and CommandComplete on NVIM v0.12.0 Jun 17, 2026
@c-c-k c-c-k changed the title update CreateCommandOpts, CommandInfos and CommandComplete on NVIM v0.12.0 breaking: Rework CreateCommandOpts, CommandInfos and CommandComplete Jun 20, 2026
@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from 5913040 to 0375a30 Compare June 20, 2026 19:39
@c-c-k c-c-k marked this pull request as ready for review June 20, 2026 20:10
* Add custom serde deserializer for `CommandComplete`.
* Rename `CommandComplete::CustomList(fun)` to `CommandComplete::Callback(fun)`.
* Add `CommandComplete::Custom(String)`.
* Add `CommandComplete::Customlist(String)`.
* Add other `CommandComplete` variants listed in the NVIM documentation.
* Add `CommandComplete` tests.
* Change `CommandInfos::complete`'s type from `String` to `CommandComplete`.
* Mark `nvim_oxi::api::get_commands` as unsafe.
* Modify `CreateCommandOpts::complete` to accept a function directly.
* Modify existing `create_user_command` tests to `get_commands` being unsafe.
@c-c-k c-c-k force-pushed the stack/025-pr-fix-user-command-completion-on-v0.12.0 branch from 0375a30 to ed6d5c9 Compare June 22, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant