Skip to content

Commit 0c5257a

Browse files
authored
Merge pull request #350 from bfredl/clientinfo
host: add client info
2 parents 5072b7b + 6614b9c commit 0c5257a

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

neovim/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
stdio_session, tcp_session)
1313
from .plugin import (Host, autocmd, command, decode, encoding, function,
1414
plugin, rpc_export, shutdown_hook)
15-
from .util import Version
15+
from .util import VERSION, Version
1616

1717

1818
__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
1919
'start_host', 'autocmd', 'command', 'encoding', 'decode',
20-
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'VERSION',
21-
'shutdown_hook', 'attach', 'setup_logging', 'ErrorResponse')
22-
23-
24-
VERSION = Version(major=0, minor=2, patch=6, prerelease='')
20+
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'Version',
21+
'VERSION', 'shutdown_hook', 'attach', 'setup_logging',
22+
'ErrorResponse')
2523

2624

2725
def start_host(session=None):

neovim/plugin/host.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55
import os
66
import os.path
77
import re
8+
import sys
89
from functools import partial
910
from traceback import format_exc
1011

1112
from . import script_host
1213
from ..api import decode_if_bytes, walk
1314
from ..compat import IS_PYTHON3, find_module
1415
from ..msgpack_rpc import ErrorResponse
15-
from ..util import format_exc_skip
16+
from ..util import VERSION, format_exc_skip
1617

1718
__all__ = ('Host')
1819

1920
logger = logging.getLogger(__name__)
2021
error, debug, info, warn = (logger.error, logger.debug, logger.info,
2122
logger.warning,)
2223

24+
host_method_spec = {"poll": {}, "specs": {"nargs": 1}, "shutdown": {}}
25+
2326

2427
class Host(object):
2528

@@ -116,6 +119,7 @@ def _missing_handler_error(self, name, kind):
116119
return msg
117120

118121
def _load(self, plugins):
122+
has_script = False
119123
for path in plugins:
120124
err = None
121125
if path in self._loaded:
@@ -124,6 +128,7 @@ def _load(self, plugins):
124128
try:
125129
if path == "script_host.py":
126130
module = script_host
131+
has_script = True
127132
else:
128133
directory, name = os.path.split(os.path.splitext(path)[0])
129134
file, pathname, descr = find_module(name, [directory])
@@ -141,6 +146,17 @@ def _load(self, plugins):
141146
error(err)
142147
self._load_errors[path] = err
143148

149+
if len(plugins) == 1 and has_script:
150+
kind = "script"
151+
else:
152+
kind = "rplugin"
153+
name = "python{}-{}-host".format(sys.version_info[0], kind)
154+
attributes = {"license": "Apache v2",
155+
"website": "github.com/neovim/python-client"}
156+
self.nvim.api.set_client_info(
157+
name, VERSION.__dict__, "host", host_method_spec,
158+
attributes, async_=True)
159+
144160
def _unload(self):
145161
for path, plugin in self._loaded.items():
146162
handlers = plugin['handlers']

neovim/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ def __repr__(self):
3030
def __eq__(self, other):
3131
"""Check if version is same as other."""
3232
return self.__dict__ == other.__dict__
33+
34+
35+
VERSION = Version(major=0, minor=2, patch=6, prerelease='')

test/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@pytest.fixture(autouse=True)
1212
def cleanup_func(vim):
13-
fun = textwrap.dedent(''':function BeforeEachTest()
13+
fun = textwrap.dedent('''function! BeforeEachTest()
1414
set all&
1515
redir => groups
1616
silent augroup
@@ -47,7 +47,7 @@ def cleanup_func(vim):
4747
comclear
4848
endfunction
4949
''')
50-
vim.input(fun)
50+
vim.command(fun)
5151
vim.command('call BeforeEachTest()')
5252
assert len(vim.tabpages) == len(vim.windows) == len(vim.buffers) == 1
5353

test/test_host.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from neovim.plugin.host import Host, host_method_spec
4+
5+
def test_host_method_spec(vim):
6+
h = Host(vim)
7+
assert h._request_handlers.keys() == host_method_spec.keys()

0 commit comments

Comments
 (0)