Problem
I'm trying to use an autocmd via the remote-plugin documentation, and running into errors.
$ python -V
Python 3.8.6
$ pip -V
pip 19.3.1 from /usr/lib/python3.8/site-packages/pip (python 3.8)
$ pip list installed | grep -i pynvim
pynvim 0.4.2
$ nvim --version
NVIM v0.5.0-812-gd17e50879
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-317a2489-aba5-414a-b9f3-9551746c326c
Setup
Looking at the generated manifest file /home/user/.local/share/nvim/rplugin.vim:
" perl plugins
" node plugins
" python3 plugins
call remote#host#RegisterPlugin('python3', '/home/user/.config/nvim/rplugin/python3/pluginctl.py', [
\ {'sync': v:true, 'name': 'Plugin', 'type': 'command', 'opts': {'nargs': '+'}},
\ {'sync': v:false, 'name': 'PluginClean', 'type': 'command', 'opts': {'nargs': '0'}},
\ {'sync': v:false, 'name': 'PluginInstall', 'type': 'command', 'opts': {'bang': '', 'nargs': '0'}},
\ ])
call remote#host#RegisterPlugin('python3', '/home/user/.config/nvim/rplugin/python3/terminalctl.py', [
\ {'sync': v:true, 'name': 'TabNew', 'type': 'autocmd', 'opts': {'pattern': '*'}},
\ {'sync': v:true, 'name': 'TerminalToggle', 'type': 'command', 'opts': {'nargs': '0'}},
\ ])
" ruby plugins
" python plugins
and then loading up a ~/.config/nvim/init.vim which only contains:
runtime! plugin/rplugin.vim | silent! UpdateRemotePlugins
and the relevant parts of /home/user/.config/nvim/rplugin/python3/terminalctl.py:
from pynvim import (
autocmd,
command,
plugin,
)
@plugin
class TerminalCtl(object):
def __init__(self, nvim):
self.nvim = nvim
@command('TerminalToggle', nargs='0', sync=True)
def _terminal_toggle(
self,
args
):
pass
@autocmd('TabNew', pattern='*', sync=True)
def _tab_id(
self,
):
pass
which is a pretty simplistic example. We can also see that Neovim recognizes the autocmd internally:
:autocmd TabNew
--- Autocommands ---
RPC_DEFINE_AUTOCMD_GROUP_1 TabNew
* call remote#define#AutocmdBootstrap("python3", "/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*", v:true, "Tab
New", {'group': 'RPC_DEFINE_AUTOCMD_GROUP_1', 'pattern': '*'}, "\"doau RPC_DEFINE_AUTOCMD_GROUP_1 TabNew \".fnameescape(expand(\"<amatch>\"))")
Note that the commands work just fine, it is the autocmds that fail.
Traceback
When I try to run :tabnew, triggering the autocmd, I get the following stack trace:
Error detected while processing function remote#define#request:
line 2:
error caught in request handler '/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:* []'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/pynvim/plugin/host.py", line 129, in _on_request
rv = handler(*args)
File "/usr/local/lib/python3.8/site-packages/pynvim/plugin/host.py", line 95, in _wrap_delayed_function
self._request_handlers[name](*args)
KeyError: '/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*'
Error invoking '/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*' on channel 4 (python3-rplugin-host):
KeyError('/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*')
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/pynvim/msgpack_rpc/session.py", line 200, in handler
rv = self._request_cb(name, args)
File "/usr/local/lib/python3.8/site-packages/pynvim/api/nvim.py", line 210, in filter_request_cb
result = request_cb(name, args)
File "/usr/local/lib/python3.8/site-packages/pynvim/plugin/host.py", line 129, in _on_request
rv = handler(*args)
File "/usr/local/lib/python3.8/site-packages/pynvim/plugin/host.py", line 95, in _wrap_delayed_function
self._request_handlers[name](*args)
so we are getting a KeyError for /home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:* in the file /usr/local/lib/python3.8/site-packages/pynvim/plugin/host.py on line 95. If I open this file, I can do something like:
if sync:
with open('/home/user/foo', 'w') as fd:
fd.write(str(self._request_handlers))
self._request_handlers[name](*args)
else:
self._notification_handlers[name](*args)
which will then write the string to /home/user/foo, opening it:
{
'poll': <function Host.__init__.<locals>.<lambda> at 0x7fad25255430>,
'specs': <bound method Host._on_specs_request of <pynvim.plugin.host.Host object at 0x7fad25252e20>>,
'shutdown': <bound method Host.shutdown of <pynvim.plugin.host.Host object at 0x7fad25252e20>>,
'/home/user/.config/nvim/rplugin/python3/pluginctl.py:command:Plugin': functools.partial(<bound method Host._wrap_function of <pynvim.plugin.host.Host object at 0x7fad25252e20>>, <bound method PluginCtl._plugin_add of <pluginctl.PluginCtl object at 0x7fad24d123a0>>, True, True, None, '/home/user/.config/nvim/rplugin/python3/pluginctl.py:command:Plugin'),
'/home/user/.config/nvim/rplugin/python3/terminalctl.py:command:TerminalToggle': functools.partial(<bound method Host._wrap_function of <pynvim.plugin.host.Host object at 0x7fad25252e20>>, <bound method TerminalCtl._terminal_toggle of <terminalctl.TerminalCtl object at 0x7fad24d12940>>, True, True, None, '/home/user/.config/nvim/rplugin/python3/terminalctl.py:command:TerminalToggle')
}
so we can see that the autocmd just isn't stored. I can change the decorator to specify sync=False, and see the same thing, but a different flavor:
Error detected while processing function remote#define#request:
line 2:
Error invoking '/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*' on channel 4 (python3-rplugin-host):
no request handler registered for "/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*"
Fin
So what am I missing here?
Problem
I'm trying to use an
autocmdvia the remote-plugin documentation, and running into errors.$ python -V Python 3.8.6 $ pip -V pip 19.3.1 from /usr/lib/python3.8/site-packages/pip (python 3.8) $ pip list installed | grep -i pynvim pynvim 0.4.2 $ nvim --version NVIM v0.5.0-812-gd17e50879 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include Compiled by travis@travis-job-317a2489-aba5-414a-b9f3-9551746c326cSetup
Looking at the generated manifest file
/home/user/.local/share/nvim/rplugin.vim:and then loading up a
~/.config/nvim/init.vimwhich only contains:and the relevant parts of
/home/user/.config/nvim/rplugin/python3/terminalctl.py:which is a pretty simplistic example. We can also see that Neovim recognizes the
autocmdinternally:Note that the commands work just fine, it is the autocmds that fail.
Traceback
When I try to run
:tabnew, triggering theautocmd, I get the following stack trace:so we are getting a
KeyErrorfor/home/user/.config/nvim/rplugin/python3/terminalctl.py:autocmd:TabNew:*in the file/usr/local/lib/python3.8/site-packages/pynvim/plugin/host.pyon line95. If I open this file, I can do something like:which will then write the string to
/home/user/foo, opening it:{ 'poll': <function Host.__init__.<locals>.<lambda> at 0x7fad25255430>, 'specs': <bound method Host._on_specs_request of <pynvim.plugin.host.Host object at 0x7fad25252e20>>, 'shutdown': <bound method Host.shutdown of <pynvim.plugin.host.Host object at 0x7fad25252e20>>, '/home/user/.config/nvim/rplugin/python3/pluginctl.py:command:Plugin': functools.partial(<bound method Host._wrap_function of <pynvim.plugin.host.Host object at 0x7fad25252e20>>, <bound method PluginCtl._plugin_add of <pluginctl.PluginCtl object at 0x7fad24d123a0>>, True, True, None, '/home/user/.config/nvim/rplugin/python3/pluginctl.py:command:Plugin'), '/home/user/.config/nvim/rplugin/python3/terminalctl.py:command:TerminalToggle': functools.partial(<bound method Host._wrap_function of <pynvim.plugin.host.Host object at 0x7fad25252e20>>, <bound method TerminalCtl._terminal_toggle of <terminalctl.TerminalCtl object at 0x7fad24d12940>>, True, True, None, '/home/user/.config/nvim/rplugin/python3/terminalctl.py:command:TerminalToggle') }so we can see that the
autocmdjust isn't stored. I can change the decorator to specifysync=False, and see the same thing, but a different flavor:Fin
So what am I missing here?