From 9e720cbea4949d65d280881d0e5f45b5a727526d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sun, 4 Nov 2018 12:56:37 +0000 Subject: [PATCH] Simplify eglot-code-action. fix compilation warning * eglot.el (eglot-code-actions): Simplify. (eglot-client-capabilities): Mention supported codeActionKind's directly. (eglot--code-action-kinds): Remove. --- lisp/progmodes/eglot.el | 77 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index b2e88d8439f..2b683f8874a 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -226,9 +226,12 @@ let the buffer grow forever." :codeAction (list :dynamicRegistration :json-false :codeActionLiteralSupport - `(:codeActionKind + '(:codeActionKind (:valueSet - [,@eglot--code-action-kinds]))) + ["quickfix" + "refactor" "refactor.extract" + "refactor.inline" "refactor.rewrite" + "source" "source.organizeImports"]))) :formatting `(:dynamicRegistration :json-false) :rangeFormatting `(:dynamicRegistration :json-false) :rename `(:dynamicRegistration :json-false) @@ -745,11 +748,6 @@ Doubles as an indicator of snippet support." (21 . "Null") (22 . "EnumMember") (23 . "Struct") (24 . "Event") (25 . "Operator") (26 . "TypeParameter"))) -(defconst eglot--code-action-kinds - '("quickfix" "refactor" "refactor.extract" - "refactor.inline" "refactor.rewrite" - "source" "source.organizeImports")) - (defun eglot--format-markup (markup) "Format MARKUP according to LSP's spec." (pcase-let ((`(,string ,mode) @@ -1786,41 +1784,40 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (unless (eglot--server-capable :codeActionProvider) (eglot--error "Server can't execute code actions!")) (let* ((server (eglot--current-server-or-lose)) - (actions (jsonrpc-request - server - :textDocument/codeAction - (list :textDocument (eglot--TextDocumentIdentifier) - :range (list :start (eglot--pos-to-lsp-position beg) - :end (eglot--pos-to-lsp-position end)) - :context - `(:diagnostics - [,@(mapcar (lambda (diag) - (cdr (assoc 'eglot-lsp-diag - (eglot--diag-data diag)))) - (flymake-diagnostics beg end))])))) - (menu-items (mapcar (jsonrpc-lambda (&key title command arguments - edit _kind _diagnostics) - `(,title . (:command ,command :arguments ,arguments - :edit ,edit))) - actions)) - (menu (and menu-items `("Eglot code actions:" ("dummy" ,@menu-items)))) - (command-and-args - (and menu - (if (listp last-nonmenu-event) - (x-popup-menu last-nonmenu-event menu) - (let ((never-mind (gensym)) retval) - (setcdr (cadr menu) - (cons `("never mind..." . ,never-mind) (cdadr menu))) - (if (eq (setq retval (tmm-prompt menu)) never-mind) - (keyboard-quit) - retval)))))) - (cl-destructuring-bind (&key _title command arguments edit) command-and-args + (actions + (jsonrpc-request + server + :textDocument/codeAction + (list :textDocument (eglot--TextDocumentIdentifier) + :range (list :start (eglot--pos-to-lsp-position beg) + :end (eglot--pos-to-lsp-position end)) + :context + `(:diagnostics + [,@(mapcar (lambda (diag) + (cdr (assoc 'eglot-lsp-diag + (eglot--diag-data diag)))) + (flymake-diagnostics beg end))])))) + (menu-items + (or (mapcar (jsonrpc-lambda (&key title command arguments + edit _kind _diagnostics) + `(,title . (:command ,command :arguments ,arguments + :edit ,edit))) + actions) + (eglot--error "No code actions here"))) + (menu `("Eglot code actions:" ("dummy" ,@menu-items))) + (action (if (listp last-nonmenu-event) + (x-popup-menu last-nonmenu-event menu) + (let ((never-mind (gensym)) retval) + (setcdr (cadr menu) + (cons `("never mind..." . ,never-mind) (cdadr menu))) + (if (eq (setq retval (tmm-prompt menu)) never-mind) + (keyboard-quit) + retval))))) + (cl-destructuring-bind (&key _title command arguments edit) action (when edit (eglot--apply-workspace-edit edit)) - (if command - (eglot-execute-command server (intern command) arguments) - (unless edit - (eglot--message "No code actions here")))))) + (when command + (eglot-execute-command server (intern command) arguments))))) -- 2.39.2