From a56c77183a9b59409701cfd78e38b5a50970857d Mon Sep 17 00:00:00 2001 From: Andrii Kolomoiets Date: Wed, 13 May 2020 10:48:26 +0300 Subject: [PATCH] Simplify eglot-code-actions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 * eglot.el (eglot-code-actions): Simplify. GitHub-reference: close https://github.com/joaotavora/eglot/issues/473 --- lisp/progmodes/eglot.el | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 8bb610bb4ed..4b25368d735 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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)) -- 2.39.2