;; This code basically copies directly from `jsonrpc' while removing ;; some parts related to sending the HTTP-like headers. (defclass hyperdrive-jsonrpc-process-connection (jsonrpc-process-connection) nil) (cl-defmethod initialize-instance ((conn hyperdrive-jsonrpc-process-connection) slots) (cl-call-next-method) (cl-destructuring-bind (&key ((:process proc)) name &allow-other-keys) slots (set-process-filter proc #'hyperdrive-jsonrpc--process-filter))) (defun hyperdrive-jsonrpc--process-filter (proc string) (when (buffer-live-p (process-buffer proc)) (with-current-buffer (process-buffer proc) (let* ((inhibit-read-only t) (connection (process-get proc 'jsonrpc-connection))) ;; Insert the text, advancing the process marker. (save-excursion (goto-char (process-mark proc)) (insert string) (set-marker (process-mark proc) (point))) (condition-case err (when-let ((json-message (jsonrpc--json-read))) (with-temp-buffer (jsonrpc-connection-receive connection json-message))) (error (message "hyperdrive-jsonrpc--process-filter ERROR:%S PROC:%S STRING:%S" err proc string))))))) (cl-defmethod jsonrpc-connection-send ((connection hyperdrive-jsonrpc-process-connection) &rest args &key _id method _params _result _error _partial) "Send MESSAGE, a JSON object, to CONNECTION." (when method (plist-put args :method (cond ((keywordp method) (substring (symbol-name method) 1)) ((and method (symbolp method)) (symbol-name method))))) (let* ((message `(:jsonrpc "2.0" ,@args)) (json (jsonrpc--json-encode message))) (process-send-string (jsonrpc--process connection) json) (jsonrpc--log-event connection message 'client)))