diff --git a/pynvim/api/nvim.py b/pynvim/api/nvim.py index aa5f3bea..8c4893b8 100644 --- a/pynvim/api/nvim.py +++ b/pynvim/api/nvim.py @@ -77,7 +77,7 @@ def from_session(cls, session): creating specialized objects from Nvim remote handles. """ session.error_wrapper = lambda e: NvimError(e[1]) - channel_id, metadata = session.request(b'vim_get_api_info') + channel_id, metadata = session.request(b'nvim_get_api_info') if IS_PYTHON3: # decode all metadata strings for python3 diff --git a/pynvim/msgpack_rpc/__init__.py b/pynvim/msgpack_rpc/__init__.py index 162606c1..e14ff404 100644 --- a/pynvim/msgpack_rpc/__init__.py +++ b/pynvim/msgpack_rpc/__init__.py @@ -8,6 +8,7 @@ from .event_loop import EventLoop from .msgpack_stream import MsgpackStream from .session import ErrorResponse, Session +from ..util import get_client_info __all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session', @@ -19,6 +20,8 @@ def session(transport_type='stdio', *args, **kwargs): msgpack_stream = MsgpackStream(loop) async_session = AsyncSession(msgpack_stream) session = Session(async_session) + session.request(b'nvim_set_client_info', + *get_client_info('client', 'remote', {}), async_=True) return session diff --git a/pynvim/msgpack_rpc/async_session.py b/pynvim/msgpack_rpc/async_session.py index 78122090..b6d19098 100644 --- a/pynvim/msgpack_rpc/async_session.py +++ b/pynvim/msgpack_rpc/async_session.py @@ -57,7 +57,7 @@ def notify(self, method, args): def run(self, request_cb, notification_cb): """Run the event loop to receive requests and notifications from Nvim. - While the event loop is running, `request_cb` and `_notification_cb` + While the event loop is running, `request_cb` and `notification_cb` will be called whenever requests or notifications are respectively available. """ diff --git a/pynvim/plugin/host.py b/pynvim/plugin/host.py index dbc7476b..7bf16298 100644 --- a/pynvim/plugin/host.py +++ b/pynvim/plugin/host.py @@ -5,7 +5,6 @@ import os import os.path import re -import sys from functools import partial from traceback import format_exc @@ -13,7 +12,7 @@ from ..api import decode_if_bytes, walk from ..compat import IS_PYTHON3, find_module from ..msgpack_rpc import ErrorResponse -from ..util import VERSION, format_exc_skip +from ..util import format_exc_skip, get_client_info __all__ = ('Host') @@ -156,17 +155,11 @@ def _load(self, plugins): error(err) self._load_errors[path] = err - if len(plugins) == 1 and has_script: - kind = "script" - else: - kind = "rplugin" - name = "python{}-{}-host".format(sys.version_info[0], kind) - attributes = {"license": "Apache v2", - "website": "github.com/neovim/pynvim"} - self.name = name + kind = ("script-host" if len(plugins) == 1 and has_script + else "rplugin-host") self.nvim.api.set_client_info( - name, VERSION.__dict__, "host", host_method_spec, - attributes, async_=True) + *get_client_info(kind, 'host', host_method_spec), + async_=True) def _unload(self): for path, plugin in self._loaded.items(): diff --git a/pynvim/util.py b/pynvim/util.py index f111a398..dac38a28 100644 --- a/pynvim/util.py +++ b/pynvim/util.py @@ -14,7 +14,6 @@ def format_exc_skip(skip, limit=None): # Taken from SimpleNamespace in python 3 class Version: - """Helper class for version info.""" def __init__(self, **kwargs): @@ -32,4 +31,12 @@ def __eq__(self, other): return self.__dict__ == other.__dict__ +def get_client_info(kind, type_, method_spec): + """Returns a tuple describing the client.""" + name = "python{}-{}".format(sys.version_info[0], kind) + attributes = {"license": "Apache v2", + "website": "github.com/neovim/pynvim"} + return (name, VERSION.__dict__, type_, method_spec, attributes) + + VERSION = Version(major=0, minor=3, patch=2, prerelease='') diff --git a/test/test_host.py b/test/test_host.py index a8b7cdbf..b10b1e12 100644 --- a/test/test_host.py +++ b/test/test_host.py @@ -2,6 +2,9 @@ from pynvim.plugin.host import Host, host_method_spec -def test_host_method_spec(vim): +def test_host_clientinfo(vim): h = Host(vim) assert h._request_handlers.keys() == host_method_spec.keys() + assert 'remote' == vim.api.get_chan_info(vim.channel_id)['client']['type'] + h._load([]) + assert 'host' == vim.api.get_chan_info(vim.channel_id)['client']['type'] diff --git a/test/test_vim.py b/test/test_vim.py index fc610437..3ad84812 100644 --- a/test/test_vim.py +++ b/test/test_vim.py @@ -12,6 +12,10 @@ def source(vim, code): os.unlink(fname) +def test_clientinfo(vim): + assert 'remote' == vim.api.get_chan_info(vim.channel_id)['client']['type'] + + def test_command(vim): fname = tempfile.mkstemp()[1] vim.command('new')