better error message when called from __init__
Minimal repro:
import neovim
@neovim.plugin
class Test:
def __init__(self, nvim):
nvim.call('strlen', 'test')
@neovim.function('TestFunc', sync=True)
def test_func(self):
pass
Place this in rplugin/python3/test.py, run :UpdateRemotePlugins, and then :call TestFunc(). You'll get a "no request handler registered" message. :call TestFunc() the second time will work.
I experienced that with a call to nvim.eval in the constructor the plugin would not be discovered anymore by :UpdateRemotePlugins - which seems to be rooted in the same problem.
That said, I'd suspect that interacting with vim directly on init is a bad practice and prone to race conditions. Instead, doing your init stuff might be safer in an event handler, e.g. on VimEnter. But surely the devs could answer that more authoritatively.
Yes, method calls should be avoided in __init__, as the plugin has no control when it is run. Perhaps we could detect this and show a better error message.