Skip to content

Commit

Permalink
Close joaotavora#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 59a65f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ customize `eglot-server-programs`:
(add-to-list 'eglot-server-programs '(foo-mode . ("foo-language-server" "--args")))
```

Let me know how well it works and we can add it to the list.
Let me know how well it works and we can add it to the list.

To skip the guess and always be prompted use `C-u M-x eglot`.

Expand Down Expand Up @@ -178,7 +178,7 @@ precise and objective about the problem as you can:
possible**. This means an empty `.emacs` init file or close to it
(just loading `eglot.el`, `company.el` and `yasnippet.el` for
example, and you don't even need `use-package.el` to do that).

2. Include the log of **LSP events** and the **stderr output** of the
server (if any). You can find the former with `M-x
eglot-events-buffer` and the latter with `M-x eglot-stderr-buffer`.
Expand All @@ -187,12 +187,12 @@ precise and objective about the problem as you can:
bootstrapping problem), you can still find these buffers in your
buffer list: they're named like `*EGLOT <project>/<major-mode>
events*` and `*EGLOT <project>/<major-mode> stderr*`.

3. If Emacs errored (you saw -- and possibly heard -- an error
message), make sure you repeat the process using `M-x
toggle-debug-on-error` so you **get a backtrace** of the error that
you should also attach to the bug report.

Some more notes: it's understandable that you report it to Eglot
first, because that's the user-facing side of the LSP experience in
Emacs, but the outcome may well be that you will have to report the
Expand Down 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 Expand Up @@ -367,7 +367,7 @@ eglot-shutdown`.
- [ ] documentLink/resolve
- [ ] textDocument/documentColor
- [ ] textDocument/colorPresentation (3.6.0)
- [x] textDocument/formatting
- [x] textDocument/formatting
- [x] textDocument/rangeFormatting
- [ ] textDocument/onTypeFormatting
- [x] textDocument/rename
Expand Down Expand Up @@ -420,7 +420,7 @@ User-visible differences:
- Server-initiated edits are confirmed with the user;
- Diagnostics work out-of-the-box (no `flycheck.el` needed);
- Smoother/more responsive (read below).

Under the hood:

- Message parser is much simpler.
Expand Down
24 changes: 12 additions & 12 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 @@ -2433,7 +2433,6 @@ potentially rename EGLOT's help buffer."
:newName ,newname))
current-prefix-arg))


(defun eglot-code-actions (&optional beg end)
"Get and offer to execute code actions between BEG and END."
(interactive
Expand Down Expand Up @@ -2466,22 +2465,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 59a65f6

Please sign in to comment.