This sweeping fix has been planned for a while, but a user recently
hit this bug as described in
https://github.com/joaotavora/eglot/discussions/1206.
More and more servers today are "multi-language", meaning can handle
more than one file type. This relies on the ':languageId' string
being set to the correct value for every buffer managed by Eglot
(TextDocumentItem in LSP parlance).
Previously this string was calculated based on an imperfect heuristic
and was wrong quite often. Many servers don't even care but some
others do, so we have to fix it.
* lisp/progmodes/eglot.el (eglot-lsp-server): Remove slots
'major-modes' and 'language-id'. Add slot 'languages'.
(eglot--major-modes, eglot--language-ids): New helpers.
(eglot--lookup-mode): Simplify or maybe complicate.
(eglot--guess-contact): Use new eglot--looup-mode. Change return
value.
(eglot): Rework docstring.
(eglot-reconnect): Use eglot--language-ids, not id.
(eglot--connect): Setup eglot--languages slot in server.
(eglot--TextDocumentItem): Finally, get correct language id.