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

From: João Távora <[email-masked]>
Date: Thu, 01 May 2025 11:03:38 +0100

Elijah Gabe Pérez <[email-masked]> writes:

> João Távora <[email-masked]> writes:
>
>> Good ideas. Patches welcome, the shorter the better, of course.
>
> Done:

Your ideas are good, but did you test your patch thoroughly?  I did, see
comments below.

>                 (overlay-buffer eglot--suggestion-overlay))
> -      (overlay-get eglot--suggestion-overlay 'eglot--suggestion-tooltip)))
> +      (eglot--mode-line-props
> +       eglot-code-action-indicator
> +       'help-echo
> +       `((mouse-1
> +          eglot-code-actions-at-mouse
> +          ,(plist-get (aref (overlay-get eglot--suggestion-overlay 'eglot--actions) 0) :title)))
> +       "Execute code actions at point\n")))

This removes the face from the mode-line indication and uses 'help-echo.
Probably should be eglot-code-action-indicator-face.

Also the blurb looks like.

   Execute code actions at point. mouse-1: extract subexpression to variable

Maybe it should be:

   mouse-1: execute code actions at point

since your second sentence is misleading, as it will actually pop a
menu, not execute the actual action right away.

>  (add-to-list
> @@ -4130,7 +4136,7 @@ eglot-code-action-suggestion
>             (when (cl-plusp (length actions))
>               (setq blurb
>                     (substitute-command-keys
> -                    (eglot--format "\\[eglot-code-actions]: %s"
> +                    (eglot--format "\\[eglot-code-actions] or
>  \\[eglot-code-actions-at-mouse]: %s"

This isn't right, did you test this?  The second part shows the user
instructions that when followed do not do what they say they do.  For me
it says:

   <f2> or M-x eglot-code-actions-at-mouse: extract subexpression to variable

I have M-x eglot-code-actions bound to <f2> of course.  In my case it
should say 'mouse-2' as that is the (default) button that pops up a
menu.  So it should be

  <f2>: extract subexpression to variable, mouse-2: execute code actions
  at point

Needless to say if I press 'M-x eglot-code-actions-at-mouse' it doesn't
work, and I get an error saying there is no mouse event when invoking
the command.  So substitute-command-keys might not be a solution here,
as you can't easily get it to be aware of the special map and not say
anything if nothing is bound there.

Even more problematic is the fact that it shows the changed blurb in the
ElDoc area, in situations where the mouse (if there even is one!) is not
hovering on the margin or fringe (if there even are fringes).

So this isn't a straightforward problem to solve, which probably
explains why I left this minor detail out.

I also feel that if the code to do this grows too complicated, it's
better to add generic utility to Emacs to solve these problems and
conditionally use it in eglot.el with a 'fboundp' check.

Good luck!

João