Subject: bug#78106: [Feature Request] EGLOT: Optionally make code action indications use mouse clicks

From: Elijah Gabe Pérez <[email-masked]>
Date: Sun, 04 May 2025 15:35:44 -0600

João Távora <[email-masked]> writes:

> Elijah Gabe Pérez <[email-masked]> writes:
>
>> For now i think that the hardcoded mouse-2 would be the best choice,
>> also I've seen in other packages (including built-in) that they does the
>> same.
>
> I suppose.  In fact it's better to have mouse-1, not mouse-2, for the
> margin and mode-line, so I changed that.  The reason we use mouse-2 for
> in-buffer diagnostics overlays is because it's bad practice to rebind
> mouse-1 there, whose meaning in an editable buffer should always be
> "place point here".

I don't have problem with rebinding mouse-2 to mouse-1, so this is fine.

>>>  (add-to-list
>>> @@ -4146,14 +4150,13 @@ eglot-code-action-suggestion
>>>               (setq tooltip
>>>                     (propertize eglot-code-action-indicator
>>>                                 'face 'eglot-code-action-indicator-face
>>> -                               'help-echo blurb
>>> +                               'help-echo "mouse-2: execute code actions at point"
>>
>> "mouse-2: execute code actions at point" will appear also in ElDoc.
>
> How?  I don't see that happening in my testing.

Then i test it wrongly, I've tested it again, and now it works fine.

> See patch after my sig.  If you're content, I can push it:
>
> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index 474245352d6..d33b0b05fd4 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -2531,7 +2531,11 @@ eglot-mode-line-action-suggestion
>    '(:eval
>      (when (and (memq 'mode-line eglot-code-action-indications)
>                 (overlay-buffer eglot--suggestion-overlay))
> -      (overlay-get eglot--suggestion-overlay 'eglot--suggestion-tooltip)))
> +      (eglot--mode-line-props
> +       eglot-code-action-indicator 'eglot-code-action-indicator-face
> +       `((mouse-1
> +          eglot-code-actions-at-mouse
> +          "execute code actions at point")))))
>    "Eglot mode line construct for at-point code actions.")
>  
>  (add-to-list
> @@ -2578,7 +2582,7 @@ eglot--diag-to-lsp-diag
>  (defvar eglot-diagnostics-map
>    (let ((map (make-sparse-keymap)))
>      (define-key map [mouse-2] #'eglot-code-actions-at-mouse)
> -    (define-key map [left-margin mouse-2] #'eglot-code-actions-at-mouse)
> +    (define-key map [left-margin mouse-1] #'eglot-code-actions-at-mouse)
>      map)
>    "Keymap active in Eglot-backed Flymake diagnostic overlays.")
>  
> @@ -4146,14 +4150,13 @@ eglot-code-action-suggestion
>               (setq tooltip
>                     (propertize eglot-code-action-indicator
>                                 'face 'eglot-code-action-indicator-face
> -                               'help-echo blurb
> +                               'help-echo "mouse-1: execute code actions at point"
>                                 'mouse-face 'highlight
>                                 'keymap eglot-diagnostics-map))
>               (save-excursion
>                 (goto-char (car bounds))
>                 (let ((ov (make-overlay (car bounds) (cadr bounds))))
>                   (overlay-put ov 'eglot--actions actions)
> -                 (overlay-put ov 'eglot--suggestion-tooltip tooltip)
>                   (overlay-put
>                    ov
>                    'before-string
>

Nothing wrong here, so this can be pushed.

-- 
                                          - E.G via GNU Emacs and Org.