Skip to content

Commit

Permalink
Close #473: simplify eglot-code-actions
Browse files Browse the repository at this point in the history
If no region is active, ask for code actions at point, even if there
are no diagnostics at point.

Co-authored-by: João Távora <joaotavora@gmail.com>

* eglot.el (eglot-code-actions): Simplify.
  • Loading branch information
muffinmad authored and joaotavora committed May 30, 2020
1 parent 2b16952 commit b34447c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -2563,15 +2563,13 @@ documentation. Honour `eglot-put-doc-in-help-buffer',
current-prefix-arg))


(defun eglot-code-actions (&optional beg end)
"Get and offer to execute code actions between BEG and END."
(defun eglot-code-actions (beg &optional end)
"Offer to execute code actions between BEG and END.
Interactively, if a region is active, BEG and END are its bounds,
else BEG is point and END is nil, which results in a request for
code actions at point"
(interactive
(let (diags)
(cond ((region-active-p) (list (region-beginning) (region-end)))
((setq diags (flymake-diagnostics (point)))
(list (cl-reduce #'min (mapcar #'flymake-diagnostic-beg diags))
(cl-reduce #'max (mapcar #'flymake-diagnostic-end diags))))
(t (list (point-min) (point-max))))))
(if (region-active-p) `(,(region-beginning) ,(region-end)) `(,(point) nil)))
(unless (eglot--server-capable :codeActionProvider)
(eglot--error "Server can't execute code actions!"))
(let* ((server (eglot--current-server-or-lose))
Expand Down

0 comments on commit b34447c

Please sign in to comment.