Skip to content

Commit

Permalink
session: set client info #399
Browse files Browse the repository at this point in the history
Set basic client info for all connections, not only host.
  • Loading branch information
justinmk committed May 25, 2019
1 parent 451d259 commit 6310063
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pynvim/api/nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pynvim/msgpack_rpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion pynvim/msgpack_rpc/async_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
17 changes: 5 additions & 12 deletions pynvim/plugin/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import os
import os.path
import re
import sys
from functools import partial
from traceback import format_exc

from . import script_host
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')

Expand Down Expand Up @@ -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():
Expand Down
9 changes: 8 additions & 1 deletion pynvim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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='')
5 changes: 4 additions & 1 deletion test/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
4 changes: 4 additions & 0 deletions test/test_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 6310063

Please sign in to comment.