tag: 1.2
commit cf4881c78ee1c5dbfc6cff151df4135358098b93
Author: João Távora <[email protected]>
Commit: João Távora <[email protected]>
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.
---
eglot.el | 77 +++++++++++++++++++++++++++++++---------------------------------
1 file changed, 37 insertions(+), 40 deletions(-)
diff --git a/eglot.el b/eglot.el
index b2e88d8..2b683f8 100644
--- a/eglot.el
+++ b/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)))))