Open wookayin opened 12 months ago
Also for vim.exec_lua
python API:
vim.lua.require("vim.F")
throws pynvim.api.common.NvimError: Cannot convert given lua type
. It calls
vim.exec_lua("return require(...)", "vim.F")
which then calls via RPC:
rpcrequest('nvim_execute_lua', "return require(...)", ["vim.F"])
This RPC request cannot convert a lua function and raises errors as expected.
Note -- this nvim_execute_lua
RPC API has a different execution mechanism than luaeval()
which uses nvim_call_function
RPC API, but very related.
Returning functions ("funcrefs") over RPC is not supported. https://github.com/neovim/neovim/issues/1898
Exactly. So on the pynvim side explicit errors should be raised as in nvim_exec_lua
case, but I guess that some fixes would need to be done on the neovim core side rather than pynvim, because the crux is that RPC requests that would evaluate to "funcrefs", e.g.,
# python (using pynvim APIs)
vim.request('nvim_call_function', 'luaeval', [ "function() end" ])
vim.request('nvim_call_function', 'eval', [ "function('has')" ])
vim.funcs.eval("function('has')")
returns null (None
) instead of errors?
:python3 vim.funcs.luaeval(...)
callsvim.call("luaeval", ...)
, which then callsnvim_call_function('luaeval', [...])
via RPC, i.e.vim.request('nvim_call_function', 'luaeval', [...])
.Below tested with nvim 0.10.x nightly (as of 11/28/2023) and pynvim 0.5.0 nightly (and 0.4.3).
Primitives are OK:
Functions are not:
and hence modules:
which should instead throw an error if conversion is not possible. Ideally it may return some "proxy" callable that delegates to the target lua function via RPC.
Also, the following seems to be neovim core's bug (or a lack of feature):