feat(api): experimental nvim__exec_lua_fast #35758

Problem:
Remote UIs can't execute lua code when a blocking prompt is waiting for
input. This is needed when implementing IME pre-edit for example.

Solution:
Add an `nvim__exec_lua_fast` experimental API function, which is allowed
to run instead of being queued until after the message has been shown.
This commit is contained in:
fredizzimo
2025-12-01 02:27:02 +02:00
committed by GitHub
parent d62bbe24cb
commit 6ebeb07c56
3 changed files with 50 additions and 0 deletions

View File

@@ -1674,6 +1674,30 @@ nvim__complete_set({index}, {opts}) *nvim__complete_set()*
• winid: (number) floating window id
• bufnr: (number) buffer id in floating window
nvim__exec_lua_fast({code}, {args}) *nvim__exec_lua_fast()*
WARNING: This feature is experimental/unstable.
EXPERIMENTAL: this API may change or be removed in the future.
Like |nvim_exec_lua()|, but can be called during |api-fast| contexts.
Execute Lua code. Parameters (if any) are available as `...` inside the
chunk. The chunk can return a value.
Only statements are executed. To evaluate an expression, prefix it with
`return`: return my_function(...)
Attributes: ~
|api-fast|
|RPC| only
Parameters: ~
• {code} (`string`) Lua code to execute
• {args} (`any[]`) Arguments to the code
Return: ~
(`any`) Return value of Lua code if present or NIL.
nvim__get_runtime({pat}, {all}, {opts}) *nvim__get_runtime()*
Find files in runtime directories

View File

@@ -156,6 +156,8 @@ API
• |nvim_echo()| can create |Progress| messages
• |nvim_open_win()| floating windows can show a 'statusline'. Plugins can use
`style='minimal'` or `:setlocal statusline=` to hide the statusline.
• Added experimental |nvim__exec_lua_fast()| to allow remote API clients to
execute code while nvim is blocking for input.
BUILD

View File

@@ -517,6 +517,30 @@ Object nvim_exec_lua(String code, Array args, Arena *arena, Error *err)
return nlua_exec(code, NULL, args, kRetObject, arena, err);
}
/// EXPERIMENTAL: this API may change or be removed in the future.
///
/// Like |nvim_exec_lua()|, but can be called during |api-fast| contexts.
///
/// Execute Lua code. Parameters (if any) are available as `...` inside the
/// chunk. The chunk can return a value.
///
/// Only statements are executed. To evaluate an expression, prefix it
/// with `return`: return my_function(...)
///
/// @param code Lua code to execute
/// @param args Arguments to the code
/// @param[out] err Details of an error encountered while parsing
/// or executing the Lua code.
///
/// @return Return value of Lua code if present or NIL.
Object nvim__exec_lua_fast(String code, Array args, Arena *arena, Error *err)
FUNC_API_SINCE(14)
FUNC_API_REMOTE_ONLY
FUNC_API_FAST
{
return nvim_exec_lua(code, args, arena, err);
}
/// Calculates the number of display cells occupied by `text`.
/// Control characters including [<Tab>] count as one cell.
///