Skip to content

Commit

Permalink
Close #386: allow for auto code-action when only one action
Browse files Browse the repository at this point in the history
* eglot.el (eglot-code-actions): add option to now show the
never-mind in tmm prompt. This allows for autmatic execution of
code actions if only one available. Uses defcustom to determine
this

* README.md: Name change

Copyright-paperwork-exempt: yes
  • Loading branch information
theothornhill committed Dec 30, 2019
1 parent 3879d57 commit d33d595
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ documentation on what these do.
- `eglot-auto-display-help-buffer`: If non-nil, automatically display
`*eglot-help*` buffer;

- `eglot-confirm-server-initiated-edits`: If non-nil, ask for confirmation
- `eglot-confirm-server-initiated-actions`: If non-nil, ask for confirmation
before allowing server to edit the source buffer's text;

There are a couple more variables that you can customize via Emacs
Expand Down
23 changes: 12 additions & 11 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ let the buffer grow forever."
:type '(choice (const :tag "No limit" nil)
(integer :tag "Number of characters")))

(defcustom eglot-confirm-server-initiated-edits 'confirm
(defcustom eglot-confirm-server-initiated-actions 'confirm
"Non-nil if server-initiated edits should be confirmed with user."
:type '(choice (const :tag "Don't show confirmation prompt" nil)
(symbol :tag "Show confirmation prompt" 'confirm)))
Expand Down Expand Up @@ -1553,7 +1553,7 @@ THINGS are either registrations or unregisterations (sic)."
(cl-defmethod eglot-handle-request
(_server (_method (eql workspace/applyEdit)) &key _label edit)
"Handle server request workspace/applyEdit"
(eglot--apply-workspace-edit edit eglot-confirm-server-initiated-edits))
(eglot--apply-workspace-edit edit eglot-confirm-server-initiated-actions))

(defun eglot--TextDocumentIdentifier ()
"Compute TextDocumentIdentifier object for current buffer."
Expand Down Expand Up @@ -2466,22 +2466,23 @@ potentially rename EGLOT's help buffer."
(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)))))
(if eglot-confirm-server-initiated-actions
(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))
(tmm-prompt menu)))))
(eglot--dcase action
(((Command) command arguments)
(eglot-execute-command server (intern command) arguments))
(((Command) command arguments)
(eglot-execute-command server (intern command) arguments))
(((CodeAction) edit command)
(when edit (eglot--apply-workspace-edit edit))
(when command
(eglot--dbind ((Command) command arguments) command
(eglot-execute-command server (intern command) arguments)))))))



;;; Dynamic registration
;;;
Expand Down

0 comments on commit d33d595

Please sign in to comment.