[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa 3e0f1c3 122/139: Misc little adjustments for reada
From: |
João Távora |
Subject: |
[elpa] externals/elpa 3e0f1c3 122/139: Misc little adjustments for readability |
Date: |
Mon, 14 May 2018 09:53:48 -0400 (EDT) |
branch: externals/elpa
commit 3e0f1c353924e36c6b90b16c1a03bf716a7521d6
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Misc little adjustments for readability
* eglot.el (eglot--log-event, eglot--process-receive)
(eglot--xref-make, xref-backend-apropos): Use cl-destructuring-bind.
(eglot--server-window/showMessageRequest): Compact.
---
eglot.el | 122 ++++++++++++++++++++++++++++++---------------------------------
1 file changed, 58 insertions(+), 64 deletions(-)
diff --git a/eglot.el b/eglot.el
index 3557303..4c5d53e 100644
--- a/eglot.el
+++ b/eglot.el
@@ -467,62 +467,58 @@ INTERACTIVE is t if called interactively."
PROC is the current process. MESSAGE is a JSON-like plist. TYPE
is a symbol saying if this is a client or server originated."
(with-current-buffer (eglot-events-buffer proc)
- (let* ((inhibit-read-only t)
- (id (plist-get message :id))
- (error (plist-get message :error))
- (method (plist-get message :method))
- (subtype (cond ((and method id) 'request)
- (method 'notification)
- (id 'reply)
- (t 'message)))
- (type
- (format "%s-%s" (or type :internal) subtype)))
- (goto-char (point-max))
- (let ((msg (format "%s%s%s:\n%s\n"
- type
- (if id (format " (id:%s)" id) "")
- (if error " ERROR" "")
- (pp-to-string message))))
- (when error
- (setq msg (propertize msg 'face 'error)))
- (insert-before-markers msg)))))
+ (cl-destructuring-bind (&key method id error &allow-other-keys) message
+ (let* ((inhibit-read-only t)
+ (subtype (cond ((and method id) 'request)
+ (method 'notification)
+ (id 'reply)
+ (t 'message)))
+ (type
+ (format "%s-%s" (or type :internal) subtype)))
+ (goto-char (point-max))
+ (let ((msg (format "%s%s%s:\n%s\n"
+ type
+ (if id (format " (id:%s)" id) "")
+ (if error " ERROR" "")
+ (pp-to-string message))))
+ (when error
+ (setq msg (propertize msg 'face 'error)))
+ (insert-before-markers msg))))))
(defun eglot--process-receive (proc message)
"Process MESSAGE from PROC."
- (let* ((id (plist-get message :id))
- (method (plist-get message :method))
- (err (plist-get message :error))
- (continuations (and id
- (not method)
- (gethash id (eglot--pending-continuations
proc)))))
- (eglot--log-event proc message 'server)
- (when err (setf (eglot--status proc) `(,err t)))
- (cond (method
- ;; a server notification or a server request
- (let* ((handler-sym (intern (concat "eglot--server-" method))))
- (if (functionp handler-sym)
- (apply handler-sym proc (append
- (plist-get message :params)
- (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)
- (let ((res (plist-get message :result)))
- (if (listp res)
- (apply (cl-first continuations) res)
- (funcall (cl-first continuations) res)))))
- (id
- (eglot--warn "Ooops no continuation for id %s" id)))
- (eglot--call-deferred proc)
- (force-mode-line-update t)))
+ (cl-destructuring-bind (&key method id error &allow-other-keys) message
+ (let* ((continuations (and id
+ (not method)
+ (gethash id (eglot--pending-continuations
proc)))))
+ (eglot--log-event proc message 'server)
+ (when error (setf (eglot--status proc) `(,error t)))
+ (cond (method
+ ;; a server notification or a server request
+ (let* ((handler-sym (intern (concat "eglot--server-" method))))
+ (if (functionp handler-sym)
+ (apply handler-sym proc (append
+ (plist-get message :params)
+ (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 error
+ (apply (cl-second continuations) error)
+ (let ((res (plist-get message :result)))
+ (if (listp res)
+ (apply (cl-first continuations) res)
+ (funcall (cl-first continuations) res)))))
+ (id
+ (eglot--warn "Ooops no continuation for id %s" id)))
+ (eglot--call-deferred proc)
+ (force-mode-line-update t))))
(defvar eglot--expect-carriage-return nil)
@@ -941,10 +937,9 @@ called interactively."
'face (if (<= type 1) 'error))
type message)
"\nChoose an option: ")
- (mapcar (lambda (obj) (plist-get obj :title)) actions)
- nil
- t
- (plist-get (elt actions 0) :title)))
+ (or (mapcar (lambda (obj) (plist-get obj :title)) actions)
+ '("OK"))
+ nil t (plist-get (elt actions 0) :title)))
(if reply
(eglot--reply process id :result (eglot--obj :title reply))
(eglot--reply process id
@@ -1181,11 +1176,11 @@ DUMMY is ignored"
(defun eglot--xref-make (name uri position)
"Like `xref-make' but with LSP's NAME, URI and POSITION."
- (xref-make name (xref-make-file-location
- (eglot--uri-to-path uri)
- ;; F!@(#*&#$)CKING OFF-BY-ONE again
- (1+ (plist-get position :line))
- (plist-get position :character))))
+ (cl-destructuring-bind (line character) position
+ (xref-make name (xref-make-file-location
+ (eglot--uri-to-path uri)
+ ;; F!@(#*&#$)CKING OFF-BY-ONE again
+ (1+ line) character))))
(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot)))
(when (eglot--server-capable :documentSymbolProvider)
@@ -1255,8 +1250,7 @@ DUMMY is ignored"
(when (eglot--server-capable :workspaceSymbolProvider)
(eglot--mapply
(eglot--lambda (&key name location &allow-other-keys)
- (let ((range (plist-get location :range))
- (uri (plist-get location :uri)))
+ (cl-destructuring-bind (&key uri range) location
(eglot--xref-make name uri (plist-get range :start))))
(eglot--request (eglot--current-process-or-lose)
:workspace/symbol
- [elpa] externals/elpa fceb6bb 090/139: Get rid of eglot--special-buffer-process, (continued)
- [elpa] externals/elpa fceb6bb 090/139: Get rid of eglot--special-buffer-process, João Távora, 2018/05/14
- [elpa] externals/elpa 714e5be 086/139: Half-baked textDocument/hover support, João Távora, 2018/05/14
- [elpa] externals/elpa e9b5e54 077/139: ETOOMANYLAMBDAS, João Távora, 2018/05/14
- [elpa] externals/elpa f257d63 089/139: * eglot.el: Reformat to shave off some lines., João Távora, 2018/05/14
- [elpa] externals/elpa 5ce9ab0 106/139: Call eglot-eldoc-function after completion finishes, João Távora, 2018/05/14
- [elpa] externals/elpa d431d41 088/139: Fix bug in hover support, João Távora, 2018/05/14
- [elpa] externals/elpa d0b7773 117/139: Reduce log chatter, João Távora, 2018/05/14
- [elpa] externals/elpa 9af84a2 124/139: Prepare to sumbit to GNU ELPA, João Távora, 2018/05/14
- [elpa] externals/elpa 9577dfc 125/139: Duh, json.el is in Emacs, and json-mode.el is useless here, João Távora, 2018/05/14
- [elpa] externals/elpa 6e76b08 100/139: Support workspace/applyEdit, João Távora, 2018/05/14
- [elpa] externals/elpa 3e0f1c3 122/139: Misc little adjustments for readability,
João Távora <=
- [elpa] externals/elpa 9bf3166 136/139: Don't define a menu if nothing to show there for now, João Távora, 2018/05/14
- [elpa] externals/elpa 1fb2bcb 132/139: Ask server for textDocument/signatureHelp if it supports it, João Távora, 2018/05/14
- [elpa] externals/elpa c7bd095 118/139: Improve eglot-eldoc-function, João Távora, 2018/05/14
- [elpa] externals/elpa ab575d2 120/139: Rename functions. eglot--request is now the synchronous one, João Távora, 2018/05/14
- [elpa] externals/elpa 8448d9b 133/139: Work with any old directory, no formal project needed, João Távora, 2018/05/14
- [elpa] externals/elpa 589e1ea 138/139: Remove an unused variable, João Távora, 2018/05/14
- [elpa] externals/elpa 571b08f 076/139: Fix the odd bug here and there, João Távora, 2018/05/14
- [elpa] externals/elpa c4ffabc 083/139: Half-decent completion support, João Távora, 2018/05/14
- [elpa] externals/elpa 71e47d2 102/139: Fix odd bugs and tweak stuff, João Távora, 2018/05/14
- [elpa] externals/elpa ecd334f 101/139: Update README, João Távora, 2018/05/14