From: Michal Krzywkowski Date: Wed, 31 Oct 2018 21:14:16 +0000 (+0100) Subject: Add support for code action literals X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~411 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=025c926301f5f8f1c5a39fbf22dec1053c90c972;p=emacs.git Add support for code action literals Code action literals allow the server to simply return a WorkspaceEdit for a code action, so the client does not have to execute a command. * eglot.el (eglot-client-capabilities): Add :codeActionLiteralSupport. (eglot--code-action-kinds): New variable. (eglot-code-actions): Apply provided WorkspaceEdit. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index e15170400d8..b2e88d8439f 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -223,7 +223,12 @@ let the buffer grow forever." :definition `(:dynamicRegistration :json-false) :documentSymbol `(:dynamicRegistration :json-false) :documentHighlight `(:dynamicRegistration :json-false) - :codeAction `(:dynamicRegistration :json-false) + :codeAction (list + :dynamicRegistration :json-false + :codeActionLiteralSupport + `(:codeActionKind + (:valueSet + [,@eglot--code-action-kinds]))) :formatting `(:dynamicRegistration :json-false) :rangeFormatting `(:dynamicRegistration :json-false) :rename `(:dynamicRegistration :json-false) @@ -740,6 +745,11 @@ 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) @@ -1788,8 +1798,10 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (cdr (assoc 'eglot-lsp-diag (eglot--diag-data diag)))) (flymake-diagnostics beg end))])))) - (menu-items (mapcar (jsonrpc-lambda (&key title command arguments) - `(,title . (:command ,command :arguments ,arguments))) + (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 @@ -1802,10 +1814,13 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (if (eq (setq retval (tmm-prompt menu)) never-mind) (keyboard-quit) retval)))))) - (cl-destructuring-bind (&key _title command arguments) command-and-args + (cl-destructuring-bind (&key _title command arguments edit) command-and-args + (when edit + (eglot--apply-workspace-edit edit)) (if command (eglot-execute-command server (intern command) arguments) - (eglot--message "No code actions here"))))) + (unless edit + (eglot--message "No code actions here"))))))