Subject: bug#67463: 30.0.50; Eglot may manage js-json-mode buffers with wrong server

From: Pengji Zhang <[email-masked]>
Date: Wed, 6 Dec 2023 20:32:39 -0500

Hi João,

On Sun, Dec 3, 2023 at 3:51 PM João Távora <[email-masked]> wrote:
>
> Nope this doesn't work.  Even the slightly more involved patch after
> my sig  doesn't work, and it correctly reports the :languageId as "json"
>
> So I think the best courses of action are 3 and 4, in that order.
>

I also think option 3 could be the best. JSON is indeed a subset of
JavaScript but that does not mean valid JSON files are also valid
JavaScript files. For instance, a bare object literal '{"a": 10}' is
not accepted by perhaps all JavaScript runtimes because it is parsed
as a block of statements. That is also why we get those invalid errors
in the example.

> Another workaround is to first start M-x eglot in some json file
> in your project.  If you have one of:
>
> . ,(eglot-alternatives '(("vscode-json-language-server" "--stdio")
>                          ("vscode-json-languageserver" "--stdio")
>                          ("json-languageserver" "--stdio"))))
>
> installed, then these json-specific servers should start to manage
> js-json-mode files in your project.  If afterwards you start M-x
> eglot in a plain js file, that server won't be (erroneously) used
> to manage JSON files.
>

Thanks! This workaround indeed works, even though it is a bit tedious
(and I honestly do not quite need a language server for JSON).

Pengji