From: João Távora Date: Wed, 16 May 2018 22:45:35 +0000 (+0100) Subject: Replace eglot--with-lsp-range with a function and pcase-let X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~566 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5db50ddd47518aa82e0be1584e7019f6ae60adbb;p=emacs.git Replace eglot--with-lsp-range with a function and pcase-let * eglot.el (eglot--with-lsp-range): Remove. (eglot--range-region): New function. (eglot--server-textDocument/publishDiagnostics) (eglot--hover-info, eglot-eldoc-function) (eglot--apply-text-edits): Use it. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index da3a09f3b22..0c11b96cbe5 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -805,14 +805,10 @@ DEFERRED is passed to `eglot--async-request', which see." "Determine if current server is capable of FEAT." (plist-get (eglot--capabilities (eglot--current-process-or-lose)) feat)) -(cl-defmacro eglot--with-lsp-range ((start end) range &body body - &aux (range-sym (cl-gensym))) - "Bind LSP RANGE to START and END. Evaluate BODY." - (declare (indent 2) (debug (sexp sexp &rest form))) - `(let* ((,range-sym ,range) - (,start (eglot--lsp-position-to-point (plist-get ,range-sym :start))) - (,end (eglot--lsp-position-to-point (plist-get ,range-sym :end)))) - ,@body)) +(defun eglot--range-region (range) + "Return region (BEG . END) that represents LSP RANGE." + (cons (eglot--lsp-position-to-point (plist-get range :start)) + (eglot--lsp-position-to-point (plist-get range :end)))) ;;; Minor modes @@ -1016,7 +1012,7 @@ called interactively." collect (cl-destructuring-bind (&key range severity _group _code source message) diag-spec - (eglot--with-lsp-range (beg end) range + (pcase-let ((`(,beg . ,end) (eglot--range-region range))) (flymake-make-diagnostic (current-buffer) beg end (cond ((<= severity 1) :error) @@ -1355,7 +1351,7 @@ DUMMY is ignored" (defun eglot--hover-info (contents &optional range) (concat (and range - (eglot--with-lsp-range (beg end) range + (pcase-let ((`(,beg . ,end) (eglot--range-region range))) (concat (buffer-substring beg end) ": "))) (mapconcat #'eglot--format-markup (append @@ -1436,7 +1432,8 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (when-buffer-window (eglot--mapply (eglot--lambda (&key range _kind) - (eglot--with-lsp-range (beg end) range + (pcase-let ((`(,beg . ,end) + (eglot--range-region range))) (let ((ov (make-overlay beg end))) (overlay-put ov 'face 'highlight) (overlay-put ov 'evaporate t) @@ -1474,7 +1471,7 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (save-restriction (widen) (save-excursion - (eglot--with-lsp-range (beg end) range + (pcase-let ((`(,beg . ,end) (eglot--range-region range))) (goto-char beg) (delete-region beg end) (insert newText))))) edits) (eglot--message "%s: Performed %s edits" (current-buffer) (length edits)))