1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-07 20:30:32 -08:00
emacs/lisp/progmodes
João Távora 1841299a11 Eglot: implement inlay hints (bug#61412, bug#61066)
Inlay hints are small text annotations to specific parts of the whole
buffer, not unlike diagnostics, but designed to help readability
instead of indicating problems.  For example, a C++ LSP server can
serve hints about positional parameter names in function calls and a
variable's automatically deduced type.  Emacs can display these hints
in many little 0-length overlays with an 'before-string property, thus
helping the user remember those types and parameter names.

Since inlay hints are potentially a large amount of data to request
from the LSP server, the implementation strives to be as parsimonious
as possible with these requests.

So, by default, inlay hints are only requested for the visible
portions of the buffer across windows showing this buffer.  This is
done by leveraging the 'window-scroll-functions' variable, making for
a reasonably complex implementation involving per-window timers.  When
scrolling a window, it may take a short amount of time for inlay hints
to "pop in".  The new user variable 'eglot-lazy-inlay-hints' can be
used to exert some control over this.

Specifically, if the variable's value is set to 'nil', then inlay
hints are greedily fetched for the whole buffer every time a change
occurs.  This is a much simpler mode of operation which may avoid
problems, but is also likely much slower in large buffers.

Also, because the inlay feature is probably visually suprising to
some, it is turned OFF by default, which is not the usual practice of
Eglot (at least not when the necessary infrastructure is present).
This decision may be changed soon.  Here's a good one-liner for
enabling it by default in every Eglot-managed buffer:

   (add-hook 'eglot-managed-mode-hook #'eglot-inlay-hints-mode)

I haven't tested inlay hints extensively across many LSP servers, so I
would appreciate any testing, both for functional edge cases and
regarding performance.  There are possibly more optimization
oportunities in the "lazy" mode of operation, like more aggressively
deleting buffer overlays that are not in visible parts of the buffer.

Though I ended up writing this one from scratch, I want to thank
Dimitry Bolopopsky <dimitri@belopopsky.com> and Chinmay Dala
<dalal.chinmay.0101@gmail.com> for suggestions and early patches.

* lisp/progmodes/eglot.el (eglot--lsp-interface-alist): Define
InlayHint.
(eglot-client-capabilities): Announce 'inlayHint' capability.
(eglot-ignored-server-capabilities): Add :inlayHintProvider.
(eglot--document-changed-hook): New helper hook.
(eglot--after-change): Use it.
(eglot-inlay-hint-face, eglot-type-hint-face)
(eglot-parameter-hint-face): New faces.
(eglot--update-hints-1, eglot--inlay-hints-after-scroll)
(eglot--inlay-hints-fully, eglot--inlay-hints-lazily): New helpers.
(eglot-lazy-inlay-hints): New user variable.
(eglot-inlay-hints-mode): New minor mode.
(eglot--maybe-activate-editing-mode): Try to activate
eglot-inlay-hints-mode.
(eglot--before-change): Remove overlays immediately in the
area being changed.
(eglot--managed-mode-off): Remove overlays.

* doc/misc/eglot.texi (Eglot Features): Mention inlay hints.
(Eglot Variables): Mention eglot-lazy-inlay-hints.
2023-02-22 19:19:12 +00:00
..
antlr-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
asm-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
autoconf.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
bat-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
bug-reference.el bug-reference: prevent match-data clobbering (bug#61395) 2023-02-10 19:22:56 +01:00
c-ts-common.el Fix c-ts-mode indentation 2023-02-06 18:29:38 -08:00
c-ts-mode.el Add declaration_list to c-ts-common-indent-type-regexp-alist 2023-02-20 15:07:56 +01:00
cc-align.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-awk.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-bytecomp.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-cmds.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-defs.el CC Mode: Fix a coding bug in c-make-keywords-re. This should fix bug #61135 2023-01-30 20:02:36 +00:00
cc-engine.el ; * lisp/progmodes/cc-engine.el: Delete trailing whitespace. 2023-01-27 11:25:08 +01:00
cc-fonts.el Merge from origin/emacs-28 2023-02-19 17:37:59 +01:00
cc-guess.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-langs.el Merge from origin/emacs-28 2023-02-19 17:37:59 +01:00
cc-menus.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-mode.el CC Mode: On removal of "typedef", remove pertinent types from c-found-types 2023-01-17 18:15:45 +00:00
cc-styles.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cc-vars.el CC Mode: Change the default value of objc-font-lock-extra-types to nil 2023-01-23 21:28:32 +00:00
cfengine.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cl-font-lock.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cmacexp.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cmake-ts-mode.el Make highlighting more regular across TS modes (bug#61205) 2023-02-05 15:50:16 +02:00
compile.el Tighten and simplify typescript compilation-mode regexps (bug#61104) 2023-02-06 17:47:00 +01:00
cperl-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
cpp.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
csharp-mode.el Fix object initializer for csharp-mode (bug#61541) 2023-02-20 13:41:30 +01:00
cwarn.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
dcl-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
dockerfile-ts-mode.el Fix dockerfile-ts-mode line continuation indentation (bug#61131) 2023-01-29 00:28:48 -08:00
ebnf-abn.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf-bnf.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf-dtd.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf-ebx.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf-iso.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf-otz.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf-yac.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebnf2ps.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ebrowse.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
eglot.el Eglot: implement inlay hints (bug#61412, bug#61066) 2023-02-22 19:19:12 +00:00
elisp-mode.el Rename native-comp-deferred-compilation into native-comp-jit-compilation 2023-02-13 17:04:22 +01:00
erts-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
etags.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
executable.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
f90.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
flymake-cc.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
flymake-proc.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
flymake.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
fortran.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
gdb-mi.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
glasses.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
go-ts-mode.el go-ts-mode: Highlight variable declarations 2023-02-06 04:42:12 +02:00
grep.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
gud.el ; * lisp/progmodes/gud.el (gud-tooltip-modes): Add ts- modes. 2023-01-07 18:44:16 -08:00
hideif.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
hideshow.el Teach 'hs-minor-mode' about tree-sitter based modes 2023-02-02 19:41:09 +02:00
icon.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
idlw-complete-structtag.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
idlw-help.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
idlw-shell.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
idlw-toolbar.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
idlwave.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
inf-lisp.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
java-ts-mode.el Add super node as a keyword 2023-02-15 18:55:17 +01:00
js.el Adjust jsx indentation 2023-02-19 20:48:06 +01:00
json-ts-mode.el Make tree-sitter based modes optional 2023-01-20 10:28:26 +02:00
ld-script.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
m4-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
make-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
meta-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
mixal-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
modula2.el Prefer defvar-keymap in modula2.el 2022-10-20 09:36:11 +02:00
octave.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
opascal.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
pascal.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
perl-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
prog-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
project.el (project-try-vc): Remove unused defvar/require 2023-02-18 15:11:13 +02:00
prolog.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
ps-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
python.el * lisp/progmodes/python.el (python--import-sources): Fix regexp (bug#61648) 2023-02-22 15:31:02 +02:00
ruby-mode.el Fix ruby-mode.el local command injection vulnerability (bug#60268) 2023-02-17 11:20:10 +01:00
ruby-ts-mode.el ruby-ts-mode: Also don't reindent 'identifier' when inside ERROR 2023-02-09 04:48:25 +02:00
rust-ts-mode.el ; * lisp/progmodes/rust-ts-mode.el (treesit-node-end): Declare. 2023-02-20 19:30:02 +02:00
scheme.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
sh-script.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
simula.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
sql.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
subword.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
tcl.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
typescript-ts-mode.el Typescript-ts-mode: Add switch case handling 2023-02-20 13:41:50 +01:00
vera-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
verilog-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
vhdl-mode.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
which-func.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
xref.el * lisp/progmodes/xref.el: Bump the version. 2023-02-19 19:01:33 +02:00
xscheme.el ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00