[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot f8bfb7e 064/139: Handle requests from server corr
From: |
João Távora |
Subject: |
[elpa] externals/eglot f8bfb7e 064/139: Handle requests from server correctly |
Date: |
Mon, 14 May 2018 09:54:55 -0400 (EDT) |
branch: externals/eglot
commit f8bfb7e26aed285167d9a41ed986894b2646ebae
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Handle requests from server correctly
* eglot.el (eglot--process-receive): Redesign.
(eglot--process-send): Take REPLY arg. Discover if message is error.
(eglot--reply): new function
(eglot--log-event): Tweak docstring.
(eglot--process-receive): Reply with -32601 if unimplemented.
(eglot--server-window/showMessageRequest)
(eglot--server-client/registerCapability): Use eglot--reply
---
eglot.el | 95 ++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 50 insertions(+), 45 deletions(-)
diff --git a/eglot.el b/eglot.el
index df03d04..332f1fe 100644
--- a/eglot.el
+++ b/eglot.el
@@ -460,7 +460,7 @@ INTERACTIVE is t if called interactively."
"Log an eglot-related event.
PROC is the current process. TYPE is an identifier. MESSAGE is
a JSON-like plist or anything else. ID is a continuation
-identifier. ERROR is non-nil if this is an error."
+identifier. ERROR is non-nil if this is a JSON-RPC error."
(with-current-buffer (eglot-events-buffer proc)
(let ((inhibit-read-only t))
(goto-char (point-max))
@@ -475,53 +475,49 @@ identifier. ERROR is non-nil if this is an error."
(defun eglot--process-receive (proc message)
"Process MESSAGE from PROC."
- (let* ((response-id (plist-get message :id))
+ (let* ((id (plist-get message :id))
+ (method (plist-get message :method))
(err (plist-get message :error))
- (continuations (and response-id
- (gethash response-id
- (eglot--pending-continuations proc)))))
+ (continuations (and id
+ (not method)
+ (gethash id (eglot--pending-continuations
proc)))))
(eglot--log-event proc
- (cond ((not response-id)
- 'server-notification)
- ((not continuations)
- 'unexpected-server-reply)
- (t
- 'server-reply))
+ (cond ((and method id) 'server-request)
+ (method 'server-notification)
+ (continuations 'server-reply)
+ ;; pyls keeps on sending these
+ (t 'unexpected-server-thingy))
message
- response-id
+ id
err)
- (when err
- (setf (eglot--status proc) '("error" t)))
- (cond ((and response-id
- (not continuations))
- (eglot--warn "Ooops no continuation for id %s" response-id))
- (continuations
- (cancel-timer (cl-third continuations))
- (remhash response-id
- (eglot--pending-continuations proc))
- (cond (err
- (apply (cl-second continuations) err))
- (t
- (apply (cl-first continuations) (plist-get message
:result)))))
- (t
+ (when err (setf (eglot--status proc) '("error" t)))
+ (cond (method
;; a server notification or a server request
- (let* ((method (plist-get message :method))
- (handler-sym (intern (concat "eglot--server-"
+ (let* ((handler-sym (intern (concat "eglot--server-"
method))))
(if (functionp handler-sym)
(apply handler-sym proc (append
(plist-get message :params)
- (let ((id (plist-get message :id)))
- (if id `(:id ,id)))))
- ;; pyls keeps on sending nil notifs for each notif we
- ;; send it, just ignore these.
- (unless (null method)
- (eglot--warn "No implemetation for notification %s yet"
- method))))))))
+ (if id `(:id ,id))))
+ (eglot--warn "No implementation of method %s yet"
+ method)
+ (when id
+ (eglot--reply
+ proc id
+ :error (eglot--obj :code -32601
+ :message "Method unimplemented"))))))
+ (continuations
+ (cancel-timer (cl-third continuations))
+ (remhash id (eglot--pending-continuations proc))
+ (if err
+ (apply (cl-second continuations) err)
+ (apply (cl-first continuations) (plist-get message :result))))
+ (id
+ (eglot--warn "Ooops no continuation for id %s" id)))))
(defvar eglot--expect-carriage-return nil)
-(defun eglot--process-send (id proc message)
+(defun eglot--process-send (id proc message &optional reply)
"Send MESSAGE to PROC (ID is optional)."
(let* ((json (json-encode message))
(to-send (format "Content-Length: %d\r\n\r\n%s"
@@ -529,9 +525,11 @@ identifier. ERROR is non-nil if this is an error."
json)))
(process-send-string proc to-send)
(eglot--log-event proc (if id
- 'client-request
+ (if reply
+ 'client-reply
+ 'client-request)
'client-notification)
- message id nil)))
+ message id (plist-get message :error))))
(defvar eglot--next-request-id 0)
@@ -627,6 +625,15 @@ identifier. ERROR is non-nil if this is an error."
:method method
:params params)))
+(cl-defun eglot--reply (process id &key result error)
+ "Reply to PROCESS's request ID with MESSAGE."
+ (eglot--process-send id process
+ (eglot--obj :jsonrpc "2.0"
+ :id nil
+ :result result
+ :error error)
+ t))
+
;;; Helpers
;;;
@@ -884,13 +891,11 @@ running. INTERACTIVE is t if called interactively."
nil
t
(plist-get (elt actions 0) :title)))
- (eglot--process-send
- id
- process
- (if reply
- (eglot--obj :result (eglot--obj :title reply))
- ;; request cancelled
- (eglot--obj :error -32800))))))
+ (if reply
+ (eglot--reply process id :result (eglot--obj :title reply))
+ (eglot--reply process id
+ :error (eglot--obj :code -32800
+ :message "User cancelled"))))))
(cl-defun eglot--server-window/logMessage
(_process &key type message)
- [elpa] externals/eglot 6689a15 026/139: Add eglot-clear-status interactive command, (continued)
- [elpa] externals/eglot 6689a15 026/139: Add eglot-clear-status interactive command, João Távora, 2018/05/14
- [elpa] externals/eglot a3545fb 050/139: Rename RPC methods for clarity, João Távora, 2018/05/14
- [elpa] externals/eglot 9665a3e 051/139: Fix textDocument/didChange, João Távora, 2018/05/14
- [elpa] externals/eglot eebd32b 059/139: When user declines to reconnect, first quit existing server, João Távora, 2018/05/14
- [elpa] externals/eglot 17e0ca4 047/139: Fix Flymake diagnostic positions, João Távora, 2018/05/14
- [elpa] externals/eglot 9d404c9 054/139: Update README.md, João Távora, 2018/05/14
- [elpa] externals/eglot 29d4103 056/139: Fix mode-line mouse-clicks from outside selected window, João Távora, 2018/05/14
- [elpa] externals/eglot b1554fc 055/139: * eglot.el (eglot--process-receive): Skip null method notifs., João Távora, 2018/05/14
- [elpa] externals/eglot 51ff863 046/139: Must re-announce didOpen after reconnect, João Távora, 2018/05/14
- [elpa] externals/eglot c95a0a4 041/139: Multiple servers per project are possible, João Távora, 2018/05/14
- [elpa] externals/eglot f8bfb7e 064/139: Handle requests from server correctly,
João Távora <=
- [elpa] externals/eglot b69302c 060/139: Make M-x eglot's interactive spec a separate function, João Távora, 2018/05/14
- [elpa] externals/eglot b657b32 068/139: Use rootUri instead of rootPath, João Távora, 2018/05/14
- [elpa] externals/eglot 7d0bf64 062/139: Workaround RLS's regusal to treat nil as empty json object, João Távora, 2018/05/14
- [elpa] externals/eglot 75495dc 033/139: Slightly more user friendly start, João Távora, 2018/05/14
- [elpa] externals/eglot fdb4de1 039/139: Simplify flymake integration, João Távora, 2018/05/14
- [elpa] externals/eglot cc183a6 043/139: Fix assorted bugs, João Távora, 2018/05/14
- [elpa] externals/eglot df5d76d 065/139: Reply to client/registerCapability (don't handle it yet), João Távora, 2018/05/14
- [elpa] externals/eglot c2862f4 063/139: Don't auto-reconnect if last attempt lasted less than 3 seconds, João Távora, 2018/05/14
- [elpa] externals/eglot f1b6485 053/139: Trim some edges and add a bunch of boring RPC methods, João Távora, 2018/05/14
- [elpa] externals/eglot 0e95167 042/139: Watch for files opened under umbrella of existing process, João Távora, 2018/05/14