joaotavora / eglot

A client for Language Server Protocol servers
GNU General Public License v3.0
2.25k stars 200 forks source link

Avoiding invoking "error" in eglot-alternatives #1434

Closed shipmints closed 2 months ago

shipmints commented 2 months ago

I'm using eglot 1.17 and I see the code is the same in the latest git.

When habitually running Emacs with debug-on-error enabled and loading a buffer that enables eglot but in a directory tree that has no lsp support, eglot-alternatives calls error, vs. just a warning, that no lsp support is available and is pretty jarring. Due to the differences in Emacs runtime behavior between the interpreter and byte compiler, it is not possible to advise eglot-alternatives with either (let ((debug-on-error)) or (with-demoted-errors to avoid error.

Would you consider an option to report lack of lsp support without invoking error?

Thank you.

joaotavora commented 2 months ago

debug-on-error is for debugging Elisp (either for developers or users debugging an error). My opinion is that you shouldn't "habitually" run Emacs with it on. My opinion is also that you shouldn't spam eglot-ensure everywhere - which I suspect you do: as the manually states, you should reserve it for hooks where you can be quite sure M-x eglot would succeed.

Due to the differences in Emacs runtime behavior between the interpreter and byte compiler, it is not possible to advise eglot-alternatives with either (let ((debug-on-error)) or (with-demoted-errors to avoid error.

No, the "differences" make absolutely no difference here, you're just advising the wrong function. eglot-alternatives is a higher order function: it returns a function. You shouldn't be advising eglot-alternatives , you should be advising its return value.