diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2026-07-29 19:09:48 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2026-07-31 21:50:04 +0200 |
| commit | 726d1a92d243a8b7cb4b221d64e4523b7a89aaf4 (patch) | |
| tree | ae28d691f0a49f59f61e283e2c220563c49a18c0 /test/functional/api/command_spec.lua | |
| parent | 917232b50875cfa1ef262b2f6d61b648fdd68102 (diff) | |
| download | rneovim-726d1a92d243a8b7cb4b221d64e4523b7a89aaf4.tar.gz rneovim-726d1a92d243a8b7cb4b221d64e4523b7a89aaf4.tar.bz2 rneovim-726d1a92d243a8b7cb4b221d64e4523b7a89aaf4.zip | |
feat(options): lua closure/function options
Problem:
Cannot assign Lua functions/closures to "func" ('completefunc',
'tagfun', …) or "expr" ('foldexpr', 'indentexpr', …) options.
Solution:
- Store "func"/"expr" options as `Callback` instead of string.
- Delete oceans of copy-pasted code.
- BREAKING: LuaRef returned via RPC/Vimscript is now represented as
`"<Lua N: file:line>"` (like what `:map` shows) instead of `nil`.
- Note: `man.vim` still uses `v:lua` string, bc it's a vimscript ftplugin.
Helped-by: Lewis Russell <lewis6991@gmail.com>
Diffstat (limited to 'test/functional/api/command_spec.lua')
| -rw-r--r-- | test/functional/api/command_spec.lua | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index 554bd5b695..7bc3790801 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -187,9 +187,10 @@ describe('nvim_get_commands', function() addr = NIL, bang = false, bar = false, - callback = NIL, -- RPC serializes Lua callback as NIL. - complete = NIL, -- RPC serializes Lua callback as NIL. - preview = NIL, -- RPC serializes Lua callback as NIL. + -- RPC serializes Lua func as "<Lua N>" (normalized below). + callback = '<Lua ?>', + complete = '<Lua ?>', + preview = '<Lua ?>', complete_arg = NIL, count = NIL, definition = '', @@ -268,6 +269,10 @@ describe('nvim_get_commands', function() ]]) -- TODO(justinmk): Order is stable but undefined. Sort before return? local commands = api.nvim_get_commands({ builtin = false }) + -- Normalize the volatile ref id in the "<Lua N>" funcref hints. + for _, k in ipairs({ 'callback', 'complete', 'preview' }) do + commands.PreviewLuaCmd[k] = (commands.PreviewLuaCmd[k]:gsub('<Lua %d+.->', '<Lua ?>')) + end eq({ Cmd2 = cmd2, Cmd3 = cmd3, |