node-client icon indicating copy to clipboard operation
node-client copied to clipboard

WIP: redesign "remote plugins", eliminate "host" concept

Open justinmk opened this issue 1 year ago • 0 comments

Problem:

The "remote plugin" concept is too complicated. https://github.com/neovim/neovim/issues/27949

Solution:

  • Let the "client" also be the "host". Eliminate the separate "host" concept and related modules.
  • Any node module that imports the "neovim" package and defines method handler(s) is a "remote module". It is loaded by Nvim same as any "node client".

TODO

  • [ ] setup() (placeholder name) attaches and calls nvim_set_client_info() with the methods defined by setHandler().
  • [ ] node scripts can't import globally-installed modules. ~~So the rplugin script will need to be run with NODE_PATH=$(npm root --quiet -g) , or would need to npm install in the local plugin directory.~~
    • [ ] most reliabe: do npm install neovim at the root of stdpath('cache') (or wherever plugins are stored)
    • [ ] yarn, pnpm, etc? 💩 ref

TEST CASE / DEMO:

Invocation

const found = findNvim({ orderBy: 'desc', minVersion: '0.9.0' })
const nvim_proc = child_process.spawn(found.matches[0].path, ['--clean', '--embed'], {});
const nvim = attach({ proc: nvim_proc });
nvim.setHandler('foo', (ev, args) => {
  nvim.logger.info('handled from remote module: "%s": args:%O', ev.name, args);
});
nvim.callFunction('rpcrequest', [(await nvim.channelId), 'foo', [42, true, 'bar']]);

Result

2024-03-26 16:47:35 INF handleRequest: foo
2024-03-26 16:47:35 DBG request received: foo
2024-03-26 16:47:35 INF handled from remote module: "foo": args:[ [ 42, true, 'bar' ] ]

justinmk avatar Mar 26 '24 15:03 justinmk