[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 3e0f1c3 122/139: Misc little adjustments for read
From: |
João Távora |
Subject: |
[elpa] externals/eglot 3e0f1c3 122/139: Misc little adjustments for readability |
Date: |
Mon, 14 May 2018 09:55:06 -0400 (EDT) |
branch: externals/eglot
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/eglot e86f9b4 073/139: New helper eglot--sync-request, (continued)
- [elpa] externals/eglot e86f9b4 073/139: New helper eglot--sync-request, João Távora, 2018/05/14
- [elpa] externals/eglot 1add335 078/139: Workaround two suspected Emacs bugs, João Távora, 2018/05/14
- [elpa] externals/eglot 889ef20 085/139: Tweak the async request engine., João Távora, 2018/05/14
- [elpa] externals/eglot 193c57d 075/139: Half-decent xref support, João Távora, 2018/05/14
- [elpa] externals/eglot fc6879f 084/139: Explain why didOpen on after-revert-hook is a bad idea, João Távora, 2018/05/14
- [elpa] externals/eglot 24466a9 096/139: When killing server, always wait 3 seconds, João Távora, 2018/05/14
- [elpa] externals/eglot fceb6bb 090/139: Get rid of eglot--special-buffer-process, João Távora, 2018/05/14
- [elpa] externals/eglot d254f97 082/139: Solve another textDocument/didChange bug, João Távora, 2018/05/14
- [elpa] externals/eglot f257d63 089/139: * eglot.el: Reformat to shave off some lines., João Távora, 2018/05/14
- [elpa] externals/eglot c7bd095 118/139: Improve eglot-eldoc-function, João Távora, 2018/05/14
- [elpa] externals/eglot 3e0f1c3 122/139: Misc little adjustments for readability,
João Távora <=
- [elpa] externals/eglot 3dcbc30 109/139: Add minimal headers, commentary and autoloads, João Távora, 2018/05/14
- [elpa] externals/eglot 71e47d2 102/139: Fix odd bugs and tweak stuff, João Távora, 2018/05/14
- [elpa] externals/eglot 05c67ee 112/139: Adjust flymake integration, João Távora, 2018/05/14
- [elpa] externals/eglot 9ff97a6 079/139: Increase request timeout length to 10 seconds, João Távora, 2018/05/14
- [elpa] externals/eglot 571b08f 076/139: Fix the odd bug here and there, João Távora, 2018/05/14
- [elpa] externals/eglot a7ddce6 080/139: Support javascript's javascript-typescript-langserver, João Távora, 2018/05/14
- [elpa] externals/eglot d40f9ac 094/139: Half-decent imenu support via textDocument/documentSymbol, João Távora, 2018/05/14
- [elpa] externals/eglot bbc64b4 087/139: Clean up client capabilities, João Távora, 2018/05/14
- [elpa] externals/eglot 9882bf2 072/139: Cleanup mistake with TextDocumentItem and TextDocumentIdentifier, João Távora, 2018/05/14
- [elpa] externals/eglot 8160cd4 071/139: Handle dynamic registration in general (but nothing specific yet), João Távora, 2018/05/14