Neovim.jl
Neovim.jl copied to clipboard
Malformed signatures for `exec` functions
I'm having trouble with calling Neovim.exec and Neovim.exec_lua. It seems the functions are not being generated properly.
Calling methods on Neovim.exec returns a single method with the signature:
[1] exec(a_src::Union{String, Vector{UInt8}}, a_output::Bool) in Neovim
With the following code:
using Neovim
nvim = nvim_env()
Neovim.exec("echo 1+1", false) # follow the signature
Neovim.exec(nvim, "echo 1+1", false) # Pass the client (as with other methods)
The first call will signal the following error:
ERROR: type String has no field client
Whereas the second will fail with:
ERROR: MethodError: no method matching exec(::NvimClient{Base.PipeEndpoint}, ::String, ::Bool)
Is this the way to send messages from Julia to vimscript? What am I doing wrong here?
(This might also be a problem with other functions, I'm not sure)
To add more context, I'm currently trying to do some evaluations in Julia, but I want to do the "UI" in vimscript or Lua, so I need a way to send messages to Julia, let the runtime spawn multiple tasks, and then let each task send back a message that can be used in a vimscript/Lua function.
Any help is appreciated
Hmm, I'll have to look into why the functions aren't being properly generated (unless you want to do so, in which case feel free!) but as a workaround you should be able to use send_request, e.g. the following should work:
using Neovim
nvim = nvim_env()
function nvim_exec(nvim :: NvimClient, src :: String, output :: Bool)
return Neovim.send_request(nvim, "nvim_exec", [src, output])
end
function nvim_exec_lua(nvim :: NvimClient, code :: String, args :: Any[])
return Neovim.send_request(nvim, "nvim_exec_lua", vcat([code], args))
end
nvim_exec(nvim, "echo 1+1", false)
# This should work I think: nvim_exec_lua(nvim, "print(1 + 1)", [])
send_request works, thanks!
The nvim_exec_lua doesn't work tho. The type of args should be Vector{Any}, but after fixing that it still fails, everything else seems fine, I'm not sure about what fails there… I'll keep using vimscript alternative for now.
The
nvim_exec_luadoesn't work tho. The type of args should beVector{Any}, but after fixing that it still fails, everything else seems fine, I'm not sure about what fails there… I'll keep using vimscript alternative for now.
Hmm, really? I tried Neovim.send_request(nvim, "nvim_exec_lua", ["print(1 + 1)", []]) after connecting to a running instance of Neovim via nvim_connect and it worked fine for me . . . .
Also, my bad on the args type there; I'm not very familiar with Julia's different types since I don't really use Julia 😅
Checked again, and I think the problem was with the vcat. The args should stay in a separate array. Here's the function that's working for me:
function nvim_exec_lua(nvim::NvimClient, code::String, args::Vector)
Neovim.send_request(nvim, "nvim_exec_lua", [code, args])
end
And for convenience, a method with no args:
function nvim_exec_lua(nvim::NvimClient, code::String)
Neovim.send_request(nvim, "nvim_exec_lua", [code, []])
end
my bad on the args type there; I'm not very familiar with Julia's different types since I don't really use Julia 😅
Nah, don't worry. I use Julia mostly for smaller scripts so I don't even annotate the types 🤷♂️