Eglot: add left-fringe code action indicator (bug#80326)

The fringe indicator uses a custom lightning-bolt bitmap, an alternative
to the margin indicator on GUI frames.  It is non-interactive, however.

* lisp/progmodes/eglot.el (eglot--fringe-action): New fringe bitmap.

(eglot-code-action-indications): Add 'left-fringe' to default value
and to docstring.  Update incompatibility note.

(eglot-code-action-suggestion): Handle 'left-fringe' indication.
This commit is contained in:
João Távora 2026-05-17 13:01:48 +01:00
parent b7825c3a27
commit 0977d5915d

View file

@ -595,15 +595,16 @@ servers."
:type 'boolean)
(defface eglot-code-action-indicator-face
'((t (:inherit font-lock-escape-face :weight bold)))
'((t (:inherit warning :weight bold)))
"Face used for code action suggestions.")
(defcustom eglot-code-action-indications
'(eldoc-hint margin)
'(eldoc-hint left-fringe margin)
"How Eglot indicates there's are code actions available at point.
Value is a list of symbols, more than one can be specified:
- `eldoc-hint': ElDoc is used to hint about at-point actions;
- `left-fringe': A special indicator appears on the left fringe;
- `margin': A special indicator appears in the margin;
- `nearby': A special indicator appears near point;
- `mode-line': A special indicator appears in the mode-line.
@ -612,10 +613,13 @@ If the list is empty, Eglot will not hint about code actions at point.
Note additionally:
- `margin' and `nearby' are incompatible. If both are specified,
the latter takes priority;
- `mode-line' only works if `eglot-mode-line-action-suggestion' exists in
`eglot-mode-line-format' (which see)."
- Some values are incompatible; if one or more of `nearby',
`left-fringe' and `margin' are specified, earlier values take
precedence.
- The indicators for many of these are customizable via
`eglot-code-action-indicator' (which see), except for `left-fringe'.
- `mode-line' only works if `eglot-mode-line-action-suggestion' exists
in `eglot-mode-line-format' (which see)."
:type '(set
:tag "Tick the ones you're interested in"
(const :tag "ElDoc textual hint" eldoc-hint)
@ -4720,6 +4724,19 @@ at point. With prefix argument, prompt for ACTION-KIND."
(eglot--code-action eglot-code-action-rewrite "refactor.rewrite")
(eglot--code-action eglot-code-action-quickfix "quickfix")
(define-fringe-bitmap 'eglot--fringe-action
[#b00000111
#b00001110
#b00011100
#b00111000
#b01111111
#b00001110
#b01011100
#b01111000
#b01110000
#b01111000]
nil nil 'center)
(defun eglot-code-action-suggestion (cb &rest _ignored)
"A member of `eldoc-documentation-functions', for suggesting actions."
(when (and (eglot-server-capable :codeActionProvider)
@ -4759,13 +4776,19 @@ at point. With prefix argument, prompt for ACTION-KIND."
(overlay-put
ov
'before-string
(cond ((memq 'nearby eglot-code-action-indications)
tooltip)
((memq 'margin eglot-code-action-indications)
(propertize ""
'display
`((margin left-margin)
,tooltip)))))
(cond
((memq 'nearby eglot-code-action-indications)
tooltip)
((and
(memq 'left-fringe eglot-code-action-indications)
(< 0 (nth 0 (window-fringes))))
(propertize
"" 'display `(left-fringe
eglot--fringe-action
eglot-code-action-indicator-face)))
((memq 'margin eglot-code-action-indications)
(propertize
"" 'display `((margin left-margin) ,tooltip)))))
(setq eglot--suggestion-overlay ov))))
(when use-text-p (funcall cb blurb))))
:hint :textDocument/codeAction)