From 408025b60611e0121a440d5e5922ca5adb6d818a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Mon, 3 Dec 2018 22:51:50 +0100 Subject: [PATCH] host: catch and show nvim_error_event --- pynvim/plugin/host.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pynvim/plugin/host.py b/pynvim/plugin/host.py index b332eb26..dbc7476b 100644 --- a/pynvim/plugin/host.py +++ b/pynvim/plugin/host.py @@ -38,7 +38,9 @@ def __init__(self, nvim): self._specs = {} self._loaded = {} self._load_errors = {} - self._notification_handlers = {} + self._notification_handlers = { + 'nvim_error_event': self._on_error_event + } self._request_handlers = { 'poll': lambda: 'ok', 'specs': self._on_specs_request, @@ -49,8 +51,16 @@ def __init__(self, nvim): self._decode_default = IS_PYTHON3 def _on_async_err(self, msg): + # uncaught python exception self.nvim.err_write(msg, async_=True) + def _on_error_event(self, kind, msg): + # error from nvim due to async request + # like nvim.command(..., async_=True) + errmsg = "{}: Async request caused an error:\n{}\n".format( + self.name, decode_if_bytes(msg)) + self.nvim.err_write(errmsg, async_=True) + def start(self, plugins): """Start listening for msgpack-rpc requests and notifications.""" self.nvim.run_loop(self._on_request, @@ -153,6 +163,7 @@ def _load(self, plugins): name = "python{}-{}-host".format(sys.version_info[0], kind) attributes = {"license": "Apache v2", "website": "github.com/neovim/pynvim"} + self.name = name self.nvim.api.set_client_info( name, VERSION.__dict__, "host", host_method_spec, attributes, async_=True)