Skip to content

Commit

Permalink
host: add client info
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Oct 8, 2018
1 parent 5072b7b commit 59112c6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
10 changes: 4 additions & 6 deletions neovim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
stdio_session, tcp_session)
from .plugin import (Host, autocmd, command, decode, encoding, function,
plugin, rpc_export, shutdown_hook)
from .util import Version
from .util import VERSION, Version


__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
'start_host', 'autocmd', 'command', 'encoding', 'decode',
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'VERSION',
'shutdown_hook', 'attach', 'setup_logging', 'ErrorResponse')


VERSION = Version(major=0, minor=2, patch=6, prerelease='')
'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'Version',
'VERSION', 'shutdown_hook', 'attach', 'setup_logging',
'ErrorResponse')


def start_host(session=None):
Expand Down
18 changes: 17 additions & 1 deletion neovim/plugin/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
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 format_exc_skip
from ..util import VERSION, format_exc_skip

__all__ = ('Host')

logger = logging.getLogger(__name__)
error, debug, info, warn = (logger.error, logger.debug, logger.info,
logger.warning,)

host_method_spec = {"poll": {}, "specs": {"nargs": 1}, "shutdown": {}}


class Host(object):

Expand Down Expand Up @@ -116,6 +119,7 @@ def _missing_handler_error(self, name, kind):
return msg

def _load(self, plugins):
has_script = False
for path in plugins:
err = None
if path in self._loaded:
Expand All @@ -124,6 +128,7 @@ def _load(self, plugins):
try:
if path == "script_host.py":
module = script_host
has_script = True
else:
directory, name = os.path.split(os.path.splitext(path)[0])
file, pathname, descr = find_module(name, [directory])
Expand All @@ -141,6 +146,17 @@ 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/python-client"}
self.nvim.api.set_client_info(
name, VERSION.__dict__, "host", host_method_spec,
attributes, async_=True)

def _unload(self):
for path, plugin in self._loaded.items():
handlers = plugin['handlers']
Expand Down
3 changes: 3 additions & 0 deletions neovim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ def __repr__(self):
def __eq__(self, other):
"""Check if version is same as other."""
return self.__dict__ == other.__dict__


VERSION = Version(major=0, minor=2, patch=6, prerelease='')
7 changes: 7 additions & 0 deletions test/test_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-

from neovim.plugin.host import Host, host_method_spec

def test_host_method_spec(vim):
h = Host(vim)
assert h._request_handlers.keys() == host_method_spec.keys()

0 comments on commit 59112c6

Please sign in to comment.