pynvim icon indicating copy to clipboard operation
pynvim copied to clipboard

better error message when called from __init__

Open tbodt opened this issue 7 years ago • 2 comments

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.

tbodt avatar Mar 31 '18 22:03 tbodt

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.

numirias avatar Apr 05 '18 21:04 numirias

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.

bfredl avatar Apr 05 '18 21:04 bfredl