Subject: bug#76423: Major-mode provided LSP server for Eglot

From: Stefan Monnier <[email-masked]>
Date: Wed, 19 Feb 2025 17:22:29 -0500

>> Eglot should make it easier for major modes to suggest which LSP
>> server to use.
>
>> The patch below would let this major modes do it with a simple:
>>
>>       (setq-local eglot-server-programs
>>                   `(bicep-ts-mode . ("dotnet" ,(bicep-langserver-path))))
>
> Wouldn't the patch make harder for the users to customize Eglot to use
> their preferred LSP server instead of the server suggested by the major
> mode?

Could be, tho it depends.
AFAIK they can't use Customize to do that because packages (like
`bicep-ts-mode.el`) modify the variable outside of Customize's control,
so currently they have to do something like:

    (add-to-list 'eglot-server-programs '(bicep-ts-mode . MYSERVER))

which may need to be adjusted to

    (with-eval-after-load 'eglot
      (add-to-list 'eglot-server-programs '(bicep-ts-mode . MYSERVER)))

or

    (with-eval-after-load 'bicep-ts-mode
      (add-to-list 'eglot-server-programs '(bicep-ts-mode . MYSERVER)))

With the variable I suggest I guess they'd have to do

    (add-hook 'bicep-ts-mode-hook
      (lambda () (setq-local eglot-server-program '(bicep-ts-mode . MYSERVER))))

I know some people find `add-hook` and `lambda` more scary than
`eval-after-load` and `add-to-list`, so I guess it would count as
"harder", yes.

Maybe we should offer an actual `defcustom` variable for user overrides,
if we care enough.  Personally, I prefer to work on making the
`add-hook+lambda` approach more accessible, because it's just very
flexible and powerful, so it's much more generally useful.
One such effort is to use `use-package` or `setup`.

        Stefan