node-client
node-client copied to clipboard
WIP: redesign "remote plugins", eliminate "host" concept
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 callsnvim_set_client_info()with themethodsdefined bysetHandler(). - [ ] 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 tonpm installin the local plugin directory.~~- [ ] most reliabe: do
npm install neovimat the root ofstdpath('cache')(or wherever plugins are stored) - [ ] yarn, pnpm, etc? 💩 ref
- [ ] most reliabe: do
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' ] ]