go-client
go-client copied to clipboard
ExecLua function will cause neovim hangup
@zchee I can confirm my lua code can works well.
func (c *Command) LspInstall(p *plugin.Plugin) ([]string, error) {
userConfig := make([]string, 0)
getUserConfig := "require('lspmeta').get_user_config_server()"
if err := c.nvim.ExecLua(getUserConfig, userConfig); err != nil {
return nil, err
}
return userConfig, nil
}
lua code
function lspmeta.get_user_config_server()
local lspconfig = npcall(require,'lspconfig')
if not lspconfig then
-- check the packer exist
if next(packer_plugins) ~= nil then
vim.cmd [[packadd nvim-lspconfig]]
lspconfig = require('lspconfig')
else
return
end
end
local configs = require('lspconfig/configs')
return vim.tbl_keys(configs)
end
@glepnir Thanks! will check it.
take code form test file. also hangup. @zchee cc
any update for this issue?
@glepnir I'd dig this issue but not yet solved...
@glepnir Could you post Go side minimal code?
It's doesn't work at least my local.
func (c *Command) LspInstall(p *plugin.Plugin) ([]string, error) {
userConfig := make([]string, 0)
getUserConfig := "require('lspmeta').get_user_config_server()"
if err := c.nvim.ExecLua(getUserConfig, userConfig); err != nil {
return nil, err
}
return userConfig, nil
}
hmm it can't work for you because you does not have lua function right? check my second image. it use the go test code from go-client
Hi @glepnir @zchee I was facing a similar issue and found out that the issue was due to the --embed
flag not being set. Because --embed
flag was not set, the RPC call to nvim_exec_lua
was hanging.
A small, working lua example is:
func hello(args []string) (int, error) {
nv, err := nvim.NewChildProcess(
ChildProcessArgs("--embed") // we need to start `nvim` with this flag. In the unit tests this was set, but not in the example above
)
if err != nil {
return 0, err
}
var result int
program := "local a, b = ... return a + b"
if err := nv.ExecLua(program, &result, 1, 2); err != nil {
return result, err
}
return result, nil
}
func main() {
plugin.Main(func(p *plugin.Plugin) error {
p.HandleFunction(&plugin.FunctionOptions{Name: "Hello"}, hello)
return nil
})
}
There was another issue #155 where setting the --embed
flag also helped with the panic issues. Given it is easy to overlook setting the --embed
flag, one way to fix this is to set --embed
flag by default. I've done so in this MR #161 , and allowed users to overwrite this behavior with another option.
Please help review and let me know what you think about this solution. Thanks!
https://github.com/neovim/go-client/assets/1814687/4b3df875-66cf-4fa4-af3e-f1e678755a1a