From: Damien Merenne Date: Wed, 28 Oct 2020 20:40:32 +0000 (+0100) Subject: Handle lsp 3.15's ispreferred code action property X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~199 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e4f4762e7acd7ee235aada8c51177a08502f5c85;p=emacs.git Handle lsp 3.15's ispreferred code action property * eglot.el (eglot--lsp-interface-alist): Add :isPreferred to CodeAction. (eglot-client-capabilities): Announce :isPreferredSupport. (eglot-code-actions): Consider preferred CodeAction item. Co-authored-by: João Távora GitHub-reference: close https://github.com/joaotavora/eglot/issues/558 --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 60bc56e8aa6..bd3bb5337ab 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -244,7 +244,7 @@ let the buffer grow forever." (eval-and-compile (defvar eglot--lsp-interface-alist `( - (CodeAction (:title) (:kind :diagnostics :edit :command)) + (CodeAction (:title) (:kind :diagnostics :edit :command :isPreferred)) (ConfigurationItem () (:scopeUri :section)) (Command ((:title . string) (:command . string)) (:arguments)) (CompletionItem (:label) @@ -576,7 +576,8 @@ treated as in `eglot-dbind'." ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" - "source" "source.organizeImports"]))) + "source" "source.organizeImports"])) + :isPreferredSupport t) :formatting `(:dynamicRegistration :json-false) :rangeFormatting `(:dynamicRegistration :json-false) :rename `(:dynamicRegistration :json-false) @@ -2516,12 +2517,19 @@ code actions at point" (cons title all)) actions) (eglot--error "No code actions here"))) + (preferred-action (cl-find-if + (jsonrpc-lambda (&key isPreferred &allow-other-keys) + isPreferred) + actions)) (menu `("Eglot code actions:" ("dummy" ,@menu-items))) (action (if (listp last-nonmenu-event) (x-popup-menu last-nonmenu-event menu) (cdr (assoc (completing-read "[eglot] Pick an action: " menu-items nil t - nil nil (car menu-items)) + nil nil (or (plist-get + preferred-action + :title) + (car menu-items))) menu-items))))) (eglot--dcase action (((Command) command arguments)