def request(cls, vimsock, channel, reqid, event, args, rspid): try: reqid = int(reqid) channel = int(channel) chinfo = cls.channel_sockets[channel] if channel not in cls.channel_sockets: logger.info("channel[%s] not in NvimHandler", channel) return sock = chinfo['sock'] # request format: # - msg[0] type, which is 0 # - msg[1] request id # - msg[2] method # - msg[3] arguments content = [0, reqid, event, args] chinfo[reqid] = [rspid, vimsock] logger.info("request channel[%s]: %s", channel, content) packed = msgpack.packb(neovim_rpc_protocol.to_client(content)) sock.send(packed) except Exception as ex: logger.exception("request failed: %s", ex)
def notify(cls, channel, event, args): try: channel = int(channel) if channel not in cls.channel_sockets: logger.info("channel[%s] not in NvimHandler", channel) return sock = cls.channel_sockets[channel]['sock'] # notification format: # - msg[0] type, which is 2 # - msg[1] method # - msg[2] arguments content = [2, event, args] logger.info("notify channel[%s]: %s", channel, content) packed = msgpack.packb(neovim_rpc_protocol.to_client(content)) sock.send(packed) except Exception as ex: logger.exception("notify failed: %s", ex)
def process_pending_requests(): logger.info("process_pending_requests") while True: item = None try: item = request_queue.get(False) f, channel, msg = item msg = neovim_rpc_protocol.from_client(msg) logger.info("get msg from channel [%s]: %s", channel, msg) # request format: # - msg[0] type, which is 0 # - msg[1] request id # - msg[2] method # - msg[3] arguments # notification format: # - msg[0] type, which is 2 # - msg[1] method # - msg[2] arguments if msg[0] == 0: #request req_typed, req_id, method, args = msg try: err = None result = _process_request(channel, method, args) except Exception as ex: logger.exception("process failed: %s", ex) # error uccor err = [1, str(ex)] result = None result = [1, req_id, err, result] logger.info("sending result: %s", result) packed = msgpack.packb(neovim_rpc_protocol.to_client(result)) f.write(packed) logger.info("sent") if msg[0] == 2: # notification req_typed, method, args = msg try: result = _process_request(channel, method, args) logger.info('notification process result: [%s]', result) except Exception as ex: logger.exception("process failed: %s", ex) except QueueEmpty as em: pass except Exception as ex: logger.exception("exception during process: %s", ex) finally: if item: request_queue.task_done() else: # item==None means the queue is empty break
def process_pending_requests(): logger.info("process_pending_requests") while True: item = None try: item = request_queue.get(False) f, channel, msg = item msg = neovim_rpc_protocol.from_client(msg) logger.info("get msg from channel [%s]: %s", channel, msg) # request format: # - msg[0] type, which is 0 # - msg[1] request id # - msg[2] method # - msg[3] arguments # notification format: # - msg[0] type, which is 2 # - msg[1] method # - msg[2] arguments if msg[0] == 0: # request req_typed, req_id, method, args = msg try: err = None result = _process_request(channel, method, args) except Exception as ex: logger.exception("process failed: %s", ex) # error uccor err = [1, str(ex)] result = None result = [1, req_id, err, result] logger.info("sending result: %s", result) packed = msgpack.packb(neovim_rpc_protocol.to_client(result)) f.write(packed) logger.info("sent") if msg[0] == 2: # notification req_typed, method, args = msg try: result = _process_request(channel, method, args) logger.info('notification process result: [%s]', result) except Exception as ex: logger.exception("process failed: %s", ex) except QueueEmpty: pass except Exception as ex: logger.exception("exception during process: %s", ex) finally: if item: request_queue.task_done() else: # item==None means the queue is empty break