[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/eglot2emacs add2926de8 114/120: Make eglot-code-actions usable n
From: |
João Távora |
Subject: |
feature/eglot2emacs add2926de8 114/120: Make eglot-code-actions usable non-interactively |
Date: |
Thu, 20 Oct 2022 07:17:08 -0400 (EDT) |
branch: feature/eglot2emacs
commit add2926de85a48e102cd11017f160f9f5ebe410d
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Make eglot-code-actions usable non-interactively
* eglot.el (eglot--read-execute-code-action): New helper.
(eglot-code-actions): Use new helper. Offer non-interactive version.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/1070
---
lisp/progmodes/eglot.el | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 918bba6210..0dff2b0d86 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3124,8 +3124,9 @@ Returns a list as described in docstring of
`imenu--index-alist'."
(let ((boftap (bounds-of-thing-at-point 'sexp)))
(list (car boftap) (cdr boftap)))))
-(defun eglot-code-actions (beg &optional end action-kind)
- "Offer to execute actions of ACTION-KIND between BEG and END.
+(defun eglot-code-actions (beg &optional end action-kind interactive)
+ "Find LSP code actions of type ACTION-KIND between BEG and END.
+Interactively, offer to execute them.
If ACTION-KIND is nil, consider all kinds of actions.
Interactively, default BEG and END to region's bounds else BEG is
point and END is nil, which results in a request for code actions
@@ -3135,8 +3136,10 @@ at point. With prefix argument, prompt for ACTION-KIND."
,(and current-prefix-arg
(completing-read "[eglot] Action kind: "
'("quickfix" "refactor.extract" "refactor.inline"
- "refactor.rewrite" "source.organizeImports")))))
- (unless (eglot--server-capable :codeActionProvider)
+ "refactor.rewrite" "source.organizeImports")))
+ t))
+ (unless (or (not interactive)
+ (eglot--server-capable :codeActionProvider))
(eglot--error "Server can't execute code actions!"))
(let* ((server (eglot--current-server-or-lose))
(actions
@@ -3154,13 +3157,20 @@ at point. With prefix argument, prompt for
ACTION-KIND."
collect it)]
,@(when action-kind `(:only [,action-kind]))))
:deferred t))
- (menu-items
- (or (cl-loop for action across actions
- ;; Do filtering ourselves, in case the `:only'
- ;; didn't go through.
- when (or (not action-kind)
- (equal action-kind (plist-get action :kind)))
- collect (cons (plist-get action :title) action))
+ ;; Redo filtering, in case the `:only' didn't go through.
+ (actions (cl-loop for a across actions
+ when (or (not action-kind)
+ (equal action-kind (plist-get a :kind)))
+ collect a)))
+ (if interactive
+ (eglot--read-execute-code-action actions server action-kind)
+ actions)))
+
+(defun eglot--read-execute-code-action (actions server &optional action-kind)
+ "Helper for interactive calls to `eglot-code-actions'"
+ (let* ((menu-items
+ (or (cl-loop for a in actions
+ collect (cons (plist-get a :title) a))
(apply #'eglot--error
(if action-kind `("No \"%s\" code actions here"
,action-kind)
`("No code actions here")))))
@@ -3169,7 +3179,7 @@ at point. With prefix argument, prompt for ACTION-KIND."
(plist-get (cdr menu-item) :isPreferred))
menu-items))
(default-action (car (or preferred-action (car menu-items))))
- (action (if (and action-kind (null (cadr menu-items)))
+ (chosen (if (and action-kind (null (cadr menu-items)))
(cdr (car menu-items))
(if (listp last-nonmenu-event)
(x-popup-menu last-nonmenu-event `("Eglot code actions:"
@@ -3179,7 +3189,7 @@ at point. With prefix argument, prompt for ACTION-KIND."
default-action)
menu-items nil t nil nil default-action)
menu-items))))))
- (eglot--dcase action
+ (eglot--dcase chosen
(((Command) command arguments)
(eglot-execute-command server (intern command) arguments))
(((CodeAction) edit command)
- feature/eglot2emacs cf0ba0197a 007/120: Add support for the mint language server, (continued)
- feature/eglot2emacs cf0ba0197a 007/120: Add support for the mint language server, João Távora, 2022/10/20
- feature/eglot2emacs ed9800041e 029/120: * eglot.el (eglot--connect): display seconds on timeout., João Távora, 2022/10/20
- feature/eglot2emacs ef0da9414e 060/120: Make eglot--plist-keys a simple (non-map.el) helper again, João Távora, 2022/10/20
- feature/eglot2emacs 5e9d78f9cf 068/120: Ensure non-null :settings param in didchangeconfiguration notif, João Távora, 2022/10/20
- feature/eglot2emacs 73f4555a0d 067/120: Add out-of-box support for futhark lsp server, João Távora, 2022/10/20
- feature/eglot2emacs 50ff73d753 073/120: Use format string instead of concat, João Távora, 2022/10/20
- feature/eglot2emacs 68fbcbd620 076/120: Reduce memory footprint of eglot--{}, João Távora, 2022/10/20
- feature/eglot2emacs 3c6356b037 088/120: Appease byte-compiler warnings about wrong use of quotes, João Távora, 2022/10/20
- feature/eglot2emacs b6e041a24b 090/120: Fix embarrassing paren-matching blunder in eglot.el, João Távora, 2022/10/20
- feature/eglot2emacs dd017359e9 097/120: Add support for jedi-language-server (again), João Távora, 2022/10/20
- feature/eglot2emacs add2926de8 114/120: Make eglot-code-actions usable non-interactively,
João Távora <=
- feature/eglot2emacs eb9d6281b5 117/120: Do use eglot-connect-timeout if eglot-sync-connect is t, João Távora, 2022/10/20
- feature/eglot2emacs 0186faf2a1 120/120: ; Merge from https://github.com/joaotavora/eglot, João Távora, 2022/10/20
- feature/eglot2emacs f199060ee0 027/120: ; * eglot.el (eglot-server-initialized-hook): fix punctuation., João Távora, 2022/10/20
- feature/eglot2emacs 8b0ea132cb 035/120: * eglot.el (eglot--server-capable): don't use obsolete name., João Távora, 2022/10/20
- feature/eglot2emacs 469835a4f2 034/120: Obsolete eglot--plist-keys in favor of map-keys, João Távora, 2022/10/20
- feature/eglot2emacs 6dba74d8cb 051/120: Defend against broken move-to-column in recent emacs, João Távora, 2022/10/20
- feature/eglot2emacs 05418a1d83 054/120: Add omnisharp support for c#, João Távora, 2022/10/20
- feature/eglot2emacs c17c3cfcbf 064/120: Check textdocumentsync/willsave cap before sending it, João Távora, 2022/10/20
- feature/eglot2emacs 2dad9298d9 061/120: Rework eglot's mode-line, João Távora, 2022/10/20
- feature/eglot2emacs f9cfefcf89 063/120: Guess language-id if manually entering server program, João Távora, 2022/10/20