neovim/node-client

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

Opened this issue · 1 comments

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

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