neovim / pynvim

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

Not registering plugin command #576

Open huberb opened 1 month ago

huberb commented 1 month ago

I'm trying to add a new command to neovim using this project. This is my code:

import pynvim
import inspect
import logging

logging.basicConfig(filename='/path/to/logs.txt', level=logging.DEBUG)
logging.debug("file loaded")

@pynvim.plugin
class TestPlugin:
    def __init__(self, nvim):
        self.nvim = nvim
        logging.debug("TestPlugin loaded")

    @pynvim.command('TestCommand', nargs='*', range='', sync=True)
    def test_command(self, args, range):
        logging.debug("TestCommand triggered")
        self.nvim.out_write("TestCommand executed\n")

my log file shows "file loaded", but nothing else. It seems like the class is never instanciated. Logging output from inside the class is never written

I'm loading this using the following lines in my init.lua:

vim.api.nvim_command("python3 import my_plugin")

Which seems to be correct. The file is loaded when starting neovim

I'm using neovim 0.10.1 and python 3.11.5

Is there anything wrong with my approach? I assumed the class will be instanciated and registered automatically

justinmk commented 1 month ago

The remote plugin concept will be removed, because it's not needed if pynvim just provides a set_handler function. See https://github.com/neovim/pynvim/issues/567

@b0o any chance you can implement set_handler in pynvim?