aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJoão Távora2023-02-21 14:14:05 +0000
committerJoão Távora2023-02-22 13:40:39 +0000
commite5c3d80355c19f39169c05599852df413d723d52 (patch)
tree136c19219e19c9c1d8381c4f3d01d35ed965ce9a /modules
parent0d5440ef678259fc69a642061c4310cdbd0fa256 (diff)
downloademacs-scratch/eglot-inlay-hints.tar.gz
emacs-scratch/eglot-inlay-hints.zip
Eglot: implement inlay hints (bug#61412, bug#61066)scratch/eglot-inlay-hints
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 not have to remember these things by heart. 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, by default this inlay feature is turned ON, which is the usual practice of Eglot when facilities are in place to enable a given feature. Although this can be tweaked by the user via 'eglot-ignored-server-capabilities' as usual, it's possible this feature is visually suprising enough to warrant an exception to the usual rule. 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. * doc/misc/eglot.texi (Eglot Features): Mention inlay hints. (Eglot Variables): Mention eglot-lazy-inlay-hints.
Diffstat (limited to 'modules')
0 files changed, 0 insertions, 0 deletions