Fork me on GitHub
#emacs
<
2022-11-01
>
weavejester22:11:06

Does anyone know how lsp-mode determines whether or not to activate for a major mode? I'm taking my first steps writing a major mode, and the first issue I'm having is that LSP expects to know about it.

ericdallo22:11:40

Yes, on lsp-mode.el there are specific major modes that will trigger specific lsps, I think it's customizable and later you could add your major mode there as default if you want

weavejester22:11:39

But I don't want LSP to trigger at all.

ericdallo22:11:30

Hum, if doesn't know about that major mode it should not ask for anything, what exactly happens?

ericdallo22:11:32

here you can see a lsp declares what major modes should be activated: https://github.com/emacs-lsp/lsp-mode/blob/master/clients/lsp-clojure.el#L439

ericdallo22:11:46

And https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L730 is the variable that you could customize it, maybe your file extension is matching some of those?

weavejester22:11:07

That's what I'd have assumed - that it would ignore modes it doesn't know about. Instead it says "Unable to calculate the languageId" and "The language you are trying to use may not have built-in support for LSP".

weavejester22:11:45

I suspect it's occurring because I'm deriving my mode from clojure-mode.

ericdallo22:11:49

Maybe something is triggering the minor-mode lsp?

ericdallo22:11:29

Hum, I didn't know derived modes would trigger lsp-mode

weavejester22:11:51

But there's nothing in clojure-mode.el that would suggest it's linked to LSP directly...

ericdallo22:11:53

Makes sense though, as in the end is a clojure-mode too

weavejester22:11:01

I guess there must be something tied to LSP that the mode inherits, but I'm not sure where to begin looking for it.

weavejester22:11:24

Looks like other people have had similar problems. It appears to be an issue with LSP not handling derived modes well.

1
weavejester22:11:33

I guess LSP mode is activated via a hook, and derived major modes inherit hooks. I could no inherit from Clojure-mode and just copy the parts I need, I guess.

ericdallo22:11:50

maybe you could try to include your major-mode to lsp-disabled-clients

weavejester22:11:21

Yeah, though I don't want to tie it to LSP.

ericdallo22:11:24

So maybe support LSP on your major mode, or add do the black list variable 😕

weavejester23:11:10

I'll ask on the LSP Discord server they have, see if they have any ideas. Otherwise I might try copying the pieces I need from clojure-mode.

ericdallo23:11:48

I'm following your thread there, probably only yoncho will know, he will be available only in about 4-5 hours though

weavejester23:11:19

I'm in no hurry

weavejester23:11:15

I've been playing around with a superset of edn, and I wanted to make a major mode to handle syntax highlighting.

ericdallo23:11:00

Sounds cool!

weavejester23:11:35

It's an excuse to learn more about emacs modes, syntax tables and font locking at least!

ericdallo23:11:07

Haha Nice, I learned a lot about it when coding lsp-mode's semantic tokens