neovim / pynvim

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

First call to function returns null #434

Closed lriuui0x0 closed 3 years ago

lriuui0x0 commented 4 years ago

I'm using the standard example plugin:

import pynvim

@pynvim.plugin
class TestPlugin(object):

    def __init__(self, nvim):
        self.nvim = nvim

    @pynvim.function('TestFunction', sync=True)
    def testfunction(self, args):
        return 3

    @pynvim.command('TestCommand', nargs='*', range='')
    def testcommand(self, args, range):
        self.nvim.current.line = ('Command with args: {}, range: {}'
                                  .format(args, range))

    @pynvim.autocmd('BufEnter', pattern='*.py', eval='expand("<afile>")', sync=True)
    def on_bufenter(self, filename):
        self.nvim.out_write('testplugin is in ' + filename + '\n')

The first time I call :echo TestFunction(), it returns v:null. The second time returns the correct number. I also observed that if you open the plugin handler file first, then it will behave correctly and returns the correct number even for the first time.

As a side question, is there a way to reload remote plugins on the fly? I tried :UpdateRemotePlugins but it doesn't work. It's really annoying to restart nvim to see changes.

dncnmcdougall commented 4 years ago

I have also experienced this problem.

I am on: NVIM v0.5.0-426-g30a6e374d Build type: Release

justinmk commented 4 years ago

is there a way to reload remote plugins on the fly? I tried :UpdateRemotePlugins but it doesn't work. It's really annoying to restart nvim to see changes.

no, unfortunately. tracked in https://github.com/neovim/neovim/issues/5532