Skip to content

Commit 6310063

Browse files
authored
session: set client info #399
Set basic client info for all connections, not only host.
1 parent 451d259 commit 6310063

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

pynvim/api/nvim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def from_session(cls, session):
7777
creating specialized objects from Nvim remote handles.
7878
"""
7979
session.error_wrapper = lambda e: NvimError(e[1])
80-
channel_id, metadata = session.request(b'vim_get_api_info')
80+
channel_id, metadata = session.request(b'nvim_get_api_info')
8181

8282
if IS_PYTHON3:
8383
# decode all metadata strings for python3

pynvim/msgpack_rpc/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .event_loop import EventLoop
99
from .msgpack_stream import MsgpackStream
1010
from .session import ErrorResponse, Session
11+
from ..util import get_client_info
1112

1213

1314
__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
@@ -19,6 +20,8 @@ def session(transport_type='stdio', *args, **kwargs):
1920
msgpack_stream = MsgpackStream(loop)
2021
async_session = AsyncSession(msgpack_stream)
2122
session = Session(async_session)
23+
session.request(b'nvim_set_client_info',
24+
*get_client_info('client', 'remote', {}), async_=True)
2225
return session
2326

2427

pynvim/msgpack_rpc/async_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def notify(self, method, args):
5757
def run(self, request_cb, notification_cb):
5858
"""Run the event loop to receive requests and notifications from Nvim.
5959
60-
While the event loop is running, `request_cb` and `_notification_cb`
60+
While the event loop is running, `request_cb` and `notification_cb`
6161
will be called whenever requests or notifications are respectively
6262
available.
6363
"""

pynvim/plugin/host.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import os
66
import os.path
77
import re
8-
import sys
98
from functools import partial
109
from traceback import format_exc
1110

1211
from . import script_host
1312
from ..api import decode_if_bytes, walk
1413
from ..compat import IS_PYTHON3, find_module
1514
from ..msgpack_rpc import ErrorResponse
16-
from ..util import VERSION, format_exc_skip
15+
from ..util import format_exc_skip, get_client_info
1716

1817
__all__ = ('Host')
1918

@@ -156,17 +155,11 @@ def _load(self, plugins):
156155
error(err)
157156
self._load_errors[path] = err
158157

159-
if len(plugins) == 1 and has_script:
160-
kind = "script"
161-
else:
162-
kind = "rplugin"
163-
name = "python{}-{}-host".format(sys.version_info[0], kind)
164-
attributes = {"license": "Apache v2",
165-
"website": "github.com/neovim/pynvim"}
166-
self.name = name
158+
kind = ("script-host" if len(plugins) == 1 and has_script
159+
else "rplugin-host")
167160
self.nvim.api.set_client_info(
168-
name, VERSION.__dict__, "host", host_method_spec,
169-
attributes, async_=True)
161+
*get_client_info(kind, 'host', host_method_spec),
162+
async_=True)
170163

171164
def _unload(self):
172165
for path, plugin in self._loaded.items():

pynvim/util.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def format_exc_skip(skip, limit=None):
1414

1515
# Taken from SimpleNamespace in python 3
1616
class Version:
17-
1817
"""Helper class for version info."""
1918

2019
def __init__(self, **kwargs):
@@ -32,4 +31,12 @@ def __eq__(self, other):
3231
return self.__dict__ == other.__dict__
3332

3433

34+
def get_client_info(kind, type_, method_spec):
35+
"""Returns a tuple describing the client."""
36+
name = "python{}-{}".format(sys.version_info[0], kind)
37+
attributes = {"license": "Apache v2",
38+
"website": "github.com/neovim/pynvim"}
39+
return (name, VERSION.__dict__, type_, method_spec, attributes)
40+
41+
3542
VERSION = Version(major=0, minor=3, patch=2, prerelease='')

test/test_host.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from pynvim.plugin.host import Host, host_method_spec
44

5-
def test_host_method_spec(vim):
5+
def test_host_clientinfo(vim):
66
h = Host(vim)
77
assert h._request_handlers.keys() == host_method_spec.keys()
8+
assert 'remote' == vim.api.get_chan_info(vim.channel_id)['client']['type']
9+
h._load([])
10+
assert 'host' == vim.api.get_chan_info(vim.channel_id)['client']['type']

test/test_vim.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def source(vim, code):
1212
os.unlink(fname)
1313

1414

15+
def test_clientinfo(vim):
16+
assert 'remote' == vim.api.get_chan_info(vim.channel_id)['client']['type']
17+
18+
1519
def test_command(vim):
1620
fname = tempfile.mkstemp()[1]
1721
vim.command('new')

0 commit comments

Comments
 (0)