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

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Apr 18, 2024

  1. WIP: eliminate "host" concept

    Problem:
    The "remote plugin" concept is too complicated. neovim/neovim#27949
    
    Solution:
    - Let the "client" also be the "host". Eliminate the separate "host"
      concept and related modules.
    - Let any node module be a "host". 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".
    
    Story:
    - The value in rplugins is:
      1. it finds the interpreter on the system
      2. it figures out how to invoke the main script with the interpreter
    
    Old architecture:
    
        nvim rplugin framework ->
          node: cli.js ->
            starts the "plugin Host"
              attaches itself to current node process
                searches for plugins and tries to load them in the node process (MULTI-TENANCY)
                  -> plugin1
                  -> plugin2
                  -> ...
    
    New architecture:
    
        nvim vim.rplugin('node', '…/plugin1.js') ->
          node: neovim.cli()
        nvim vim.rplugin('node', '…/plugin2.js') ->
          node: neovim.cli()
    
    1. A Lua plugin calls `vim.rplugin('node', '/path/to/plugin.js')`.
    2. Each call to `vim.rplugin()` starts a new node process (no "multi-tenancy").
    3. plugin.js is just a normal javascript file that imports the `neovim` package.
    4. plugin.js provides a "main" function. It can simply import the `neovim.cli()` util function, which handles attaching/setup.
    
    TEST CASE / DEMO:
    
        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']]);
    
        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 committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    8982da5 View commit details
    Browse the repository at this point in the history