예제 #1
0
파일: protocol.py 프로젝트: haikulang/pygls
 def _execute_request_err_callback(self, msg_id, exc):
     """Error callback used for coroutine request message."""
     exc_info = (type(exc), exc, None)
     error = JsonRpcInternalError.of(exc_info).to_dict()
     logger.exception('Exception occurred for message "%s": %s', msg_id,
                      error)
     self._send_response(msg_id, error=error)
예제 #2
0
파일: protocol.py 프로젝트: 0keita/configs
    def _execute_notification_callback(self, future):
        """Success callback used for coroutine notification message."""
        if future.exception():

            try:
                raise future.exception()
            except Exception:
                error = JsonRpcInternalError.of(sys.exc_info()).to_dict()
                logger.exception('Exception occurred in notification: "%s"', error)
예제 #3
0
파일: protocol.py 프로젝트: 0keita/configs
    def _check_ret_type_and_send_response(self, method_name, method_type, msg_id, result):
        """Check if registered feature returns appropriate result type."""
        if method_type == ATTR_FEATURE_TYPE:
            return_type = get_method_return_type(method_name)
            if not is_instance(result, return_type):
                error = JsonRpcInternalError().to_dict()
                self._send_response(msg_id, error=error)

        self._send_response(msg_id, result=result)
예제 #4
0
파일: protocol.py 프로젝트: 0keita/configs
 def _execute_request_callback(self, method_name, method_type, msg_id, future):
     """Success callback used for coroutine request message."""
     try:
         if not future.cancelled():
             self._check_ret_type_and_send_response(
                 method_name, method_type, msg_id, result=future.result())
         else:
             self._send_response(
                 msg_id,
                 error=JsonRpcRequestCancelled(f'Request with id "{msg_id}" is canceled')
             )
         self._client_request_futures.pop(msg_id, None)
     except Exception:
         error = JsonRpcInternalError.of(sys.exc_info()).to_dict()
         logger.exception('Exception occurred for message "%s": %s', msg_id, error)
         self._send_response(msg_id, error=error)
예제 #5
0
파일: protocol.py 프로젝트: 0keita/configs
    def _handle_request(self, msg_id, method_name, params):
        """Handles a request from the client."""
        try:
            handler = self._get_handler(method_name)

            # workspace/executeCommand is a special case
            if method_name == WORKSPACE_EXECUTE_COMMAND:
                handler(params, msg_id)
            else:
                self._execute_request(msg_id, handler, params)

        except JsonRpcException as e:
            logger.exception('Failed to handle request %s %s %s', msg_id, method_name, params)
            self._send_response(msg_id, None, e.to_dict())
        except Exception:
            logger.exception('Failed to handle request %s %s %s', msg_id, method_name, params)
            err = JsonRpcInternalError.of(sys.exc_info()).to_dict()
            self._send_response(msg_id, None, err)