Skip to content

Commit

Permalink
Merge pull request #372 from bfredl/error_event
Browse files Browse the repository at this point in the history
host: catch and show nvim_error_event
  • Loading branch information
bfredl authored Dec 7, 2018
2 parents f5ea5ab + 408025b commit c608e53
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pynvim/plugin/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c608e53

Please sign in to comment.