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

From: João Távora <[email-masked]>
Date: Thu, 20 Feb 2025 23:55:48 +0000

On Thu, Feb 20, 2025 at 9:12 PM Stefan Monnier <[email-masked]> wrote:
>
> >>       (setq-local eglot-server-programs
> >>                   `(bicep-ts-mode . ("dotnet"
> >>       ,(bicep-langserver-path))))
> >
> > You mean eglot-server-program, singular (that's what your patch proposes)
>
> Oops, yes.
>
> > Anyway, your patch is more or less what I had in mind altough:
> >
> > * The name should probably be something less confusable with
> >   e-s-programs, like eglot-suggested-servers or eglot-preferred-servers
> >   (note that it can still be "servers!" unless we purposedly cap that
> >   ability, which we maybe should).
>
> I have no opinion on the name.
>
> > * It's a bit silly to repeat the major-mode symbol in it.  So the
> >   setting in the major-mode function should be something like
> >
> >     (setq eglot-suggested-servers '("dotnet" ,(bicep-langserver-path)))
>
> That's what I started with but then I saw that `eglot--lookup-mode`
> returns info that includes part of the `car` of the elements in
> `eglot-server-programs` (IIUC it's so as to know which other buffers and
> major modes could share the same server), so rather than try and learn
> how that part of Eglot really works, I went for a simpler change.

Right, I see. But to do these kinds of changes to Eglot, "how Eglot
really works" is a prerequisite :-)  And you have understood it,
in essence.

The thing is, we're going to bump into that old "mapping the language"
can of worms eventually. Language servers are for languages, so
as it stands what major modes may want to say is "I want to participate
in managing this language".  But even that is fairly awkward.  To do
this right, we'd really need a language hook. And I have 0 time to open
that can of worms.

As it stands, looking at the `eval-after-load' code for bicep-ts-mode,
I wonder if it is really a "funny dance" or just the way it should be
until past decisions are revisited (but not by me :-))

João