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

Remote plugins: Add support for registering functions after host is loaded #356

Open
saidelike opened this issue May 4, 2024 · 1 comment

Comments

@saidelike
Copy link

saidelike commented May 4, 2024

problems

I am encountering this error https://github.com/neovim/neovim/blob/3a8265266e0c0fe31f34b7c0192e8ae7d83ae950/runtime/autoload/remote/host.vim#L81 when trying to register a node function after the node host has already been started.

it would be nice to support registering node functions after the node host has started to allow easy deployment of node plugins.

details

I currently have a single neovim plugin which contains 2 node clients.

I am registering functions for both node clients myself from my own vim/lua scripts (instead of using rplugins.vim) to avoid having the user to call :UpdateRemotePlugins https://github.com/hands-free-vim/cursorless.nvim/blob/7165f98896affa68f38ebe6f6402ce7819078193/vim/cursorless.vim :

function RegisterFunctions(cursorless_nvim_path)
     call remote#host#RegisterPlugin('node', a:cursorless_nvim_path . '/node/command-server', [
          \ {'sync': v:false, 'name': 'CommandServerLoadExtension', 'type': 'function', 'opts': {}},
          \ {'sync': v:false, 'name': 'CommandServerRunCommand', 'type': 'function', 'opts': {}},
          \ ])
     call remote#host#RegisterPlugin('node', a:cursorless_nvim_path . 'node/cursorless-neovim', [
          \ {'sync': v:false, 'name': 'CursorlessLoadExtension', 'type': 'function', 'opts': {}},
          \ ])
endfunction

Then I call CommandServerLoadExtension and CursorlessLoadExtension when my neovim plugin is initialized https://github.com/hands-free-vim/cursorless.nvim/blob/7165f98896affa68f38ebe6f6402ce7819078193/lua/cursorless/init.lua#L41 :

local function load_extensions()
  vim.api.nvim_call_function('CursorlessLoadExtension', {})
  vim.api.nvim_call_function('CommandServerLoadExtension', {})

this worked fine.

Now I want to split the 2 node clients into 2 different neovim node plugins.

The first node plugin will register the CommandServer* node functions and call the node function fine (CommandServerLoadExtension).

However, from calling this function, the node host is started and it is impossible to register any other node function (CursorlessLoadExtension) in my second node plugin due to https://github.com/neovim/neovim/blob/3a8265266e0c0fe31f34b7c0192e8ae7d83ae950/runtime/autoload/remote/host.vim#L81

@justinmk
Copy link
Member

justinmk commented May 5, 2024

All of the remote#host#RegisterPlugin and "remote plugin" garbage will be removed, with the idea being to support exactly what you have requested here: any module can simply call setHandler() to define handlers for incoming requests. Then a "remote plugin" is simply a node module that imports the neovim node-client and defines handlers.

This is implemented in #344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants