Subject: bug#67609: 29.1; (eglot-inlay-hints-mode -1) behaves surprisingly, does not work in cc-mode hooks

From: João Távora <[email-masked]>
Date: Sun, 3 Dec 2023 18:52:37 +0000

On Sun, Dec 3, 2023 at 6:35 PM Morgon Kanter <[email-masked]> wrote:
>
> eglot-inlay-hints-mode seems to always turn on, at least in cc-mode, even
> when explicitly disabled by a hook, leaving me to disable it once the
> buffer is loaded. For example, this is my config:
>
> (defun config:cc-defaults ()
>   (c-toggle-comment-style 1)
>   (subword-mode 1)
>   (diminish 'subword-mode)
>   (local-set-key (kbd "C-M-S-<backspace>") #'kill-outer-sexp-and-parens)
>   ;; Run eglot if we're under a project.
>   (when (project-current)
>     (eglot-ensure)
>     (eglot-inlay-hints-mode -1)))
> (add-hook 'c-mode-common-hook #'config:cc-defaults)

Hi.  Because you're using 'eglot-ensure' (hint, maybe you
shoudn't, read the manual in the latest master for why)
it means that after the eglot-ensure form executes,
Eglot will not be setup yet, so the following form
has no effect.  You need to replace it with

  (add-hook 'eglot-managed-mode-hook (lambda ()
(eglot-inlay-hints-mode -1)) nil t)

So that when Eglot does start up, it knows to disable
inlay hints.

You may add the above line globally (with the trailing 'nil t') if
you never want inlay hints to be enabled automatically in any
mode or language server.

And see also eglot-ignored-server-capabilities and add consider
:inlayHintProvider to it if you don't even ever want to enable
it manually.

João