Closed minikN closed 6 months ago
If I misunderstood the spec or something in eglot I apologize in advance.
No need to apologize, but you should rather refer to Emacs's commits, not this repository, because Eglot's development happens in Emacs.
Here, I think the problem here is simply that js-jsx-mode
derives from js-mode
. So any buffer that is in js-jsx-mode
is -- by definition -- also in js-mode
. So this is ultimately question of major mode design.
But it's also a real problem (I presume) and is not an easy question to solve. There are attempts to solve it. I participated in one of those attempts with multiple ideas -- designed at more closely associating major modes with languages -- but my ideas were not accepted. I have since abandoned those discussions, and I plan to keep doing that. But I encourage you to participate:
bug#68246 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68246 bug#68217: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68217
I've been away from them for quite a while now (again, I plan to stay away, so please don't CC me). @monnier had a solution ready, perhaps it will work here too.
When working with a project that is supposed to have different language-ids for different file types (I test it with a js CRA application) eglot seems to send the correct
language-id
for the first file I open, but doesn't change it accordingly if I open a file of a different type afterwards (unless I'm misunderstanding the spec and this isn't suppose to happen anyway).I am aware of commit 2fbcab293e and tried to configure eglot correctly in two ways:
(put 'js-mode 'eglot-language-id "javascript") (put 'js-jsx-mode 'eglot-language-id "javascriptreact")
(with-eval-after-load 'eglot (add-to-list 'eglot-server-programs '((js-mode js-jsx-mode) . ("/gnu/store/928xbf54h864yz55j90m29f09l5bkp07-node-typescript-language-server-0.11.1/bin/typescript-language-server" "--stdio" :initializationOptions (:tsserver (:path "/gnu/store/807nkysq2myq6dgb3fsa0padsbin5rl0-node-typescript-4.7.3/lib/node_modules/typescript/lib"))))))
(get 'js-mode 'eglot-language-id) => "javascript" (get 'js-jsx-mode 'eglot-language-id) => "javascriptreact"
But the
languageId
I see in the events buffer are the same.Here are two examples:
App.js
, thenTest.jsx
: http://paste.debian.net/1313114/Test.jsx
, thenApp.js
: http://paste.debian.net/1313112/ (I restarted emacs inbetween)MRE:
emacs -Q
(with-eval-after-load 'eglot (add-to-list 'eglot-server-programs '(((js-jsx-mode :language-id "javascriptreact") (js-mode :language-id "javascript")) . ("/gnu/store/928xbf54h864yz55j90m29f09l5bkp07-node-typescript-language-server-0.11.1/bin/typescript-language-server" "--stdio" :initializationOptions (:tsserver (:path "/gnu/store/807nkysq2myq6dgb3fsa0padsbin5rl0-node-typescript-4.7.3/lib/node_modules/typescript/lib"))))))