Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecLua function will cause neovim hangup #104

Closed
glepnir opened this issue Mar 5, 2021 · 7 comments · Fixed by #161
Closed

ExecLua function will cause neovim hangup #104

glepnir opened this issue Mar 5, 2021 · 7 comments · Fixed by #161
Assignees

Comments

@glepnir
Copy link
Member

glepnir commented Mar 5, 2021

@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
@zchee
Copy link
Member

zchee commented Mar 5, 2021

@glepnir Thanks! will check it.

@zchee zchee self-assigned this Mar 5, 2021
@zchee zchee added the area/nvim label Mar 5, 2021
@glepnir
Copy link
Member Author

glepnir commented Mar 10, 2021

take code form test file. also hangup. @zchee cc

Untitled

@glepnir
Copy link
Member Author

glepnir commented Mar 12, 2021

any update for this issue?

@zchee
Copy link
Member

zchee commented Mar 14, 2021

@glepnir I'd dig this issue but not yet solved...

@zchee
Copy link
Member

zchee commented Mar 16, 2021

@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
}

@glepnir
Copy link
Member Author

glepnir commented Mar 16, 2021

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

9Y5 added a commit to 9Y5/go-client that referenced this issue Jul 14, 2023
@9Y5
Copy link
Contributor

9Y5 commented Jul 14, 2023

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!

Screen.Recording.2023-07-15.at.5.05.56.PM.mov

zchee pushed a commit that referenced this issue Jul 16, 2023
* [#104] Add --embed flag by default. Added option to disable this default behavior.

* Fix labeler to run on forks.

* Update Comment

---------

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants