neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.54k stars 120 forks source link

simplify remote plugins #567

Open justinmk opened 7 months ago

justinmk commented 7 months ago

Problem

The design, and usage, of remote plugins can be simplified, as described in https://github.com/neovim/neovim/issues/27949

tl;dr:

Solution

Reference

Implementation in node-client: https://github.com/neovim/node-client/pull/344

Related work here (this Nvim RPC application does not use rplugins, it sets up its own RPC methods which can be called from the Nvim peer): https://github.com/b0o/blender.nvim/blob/eb495c3d7217efb4bdec4e50d1f9be1372d33e2c/blender_nvim/rpc.py#L115-L127

Since I'm attaching to neovim from an external python program, not as an rplugin, pynvim doesn't start its event loop by default. So I'm spawning a new thread, and starting pynvim's event loop on it. I'm also registering request/notification handlers which I call when pynvim receives RPC messages from neovim. I'm using an "executor" to run the registered callbacks on the main thread. It's working great.