Eglot: fix bug in eglot--lookup-mode

When lookup in eglot-server-programs fails, fall back to a
half-decent (((foo-mode . "foo")) . nil) return value.  This
enables interactive M-x eglot for modes not yet registered in
e-s-p.

* lisp/progmodes/eglot.el (eglot--lookup-mode): Fallback when
lookup fails.
This commit is contained in:
João Távora 2025-02-07 20:33:41 +00:00
parent 0c0f5f5df2
commit 7169a5d563

View file

@ -1322,22 +1322,28 @@ in `eglot-server-programs' (which see).
CONTACT-PROXY is the value of the corresponding
`eglot-server-programs' entry."
(cl-loop
with lang-from-sym = (lambda (sym &optional language-id)
(cons sym
(or language-id
(or (get sym 'eglot-language-id)
(replace-regexp-in-string
"\\(?:-ts\\)?-mode$" ""
(symbol-name sym))))))
for (modes . contact) in eglot-server-programs
for llists = (mapcar #'eglot--ensure-list
(if (or (symbolp modes) (keywordp (cadr modes)))
(list modes) modes))
(if (or (symbolp modes) (keywordp (cadr modes)))
(list modes) modes))
for normalized = (mapcar (jsonrpc-lambda (sym &key language-id &allow-other-keys)
(cons sym
(or language-id
(or (get sym 'eglot-language-id)
(replace-regexp-in-string
"\\(?:-ts\\)?-mode$" ""
(symbol-name sym))))))
(funcall lang-from-sym sym language-id))
llists)
when (cl-some (lambda (cell)
(provided-mode-derived-p mode (car cell)))
normalized)
return (cons normalized contact)))
return (cons normalized contact)
;; If lookup fails at least return some suitable LANGUAGES.
finally (cl-return
(cons (list (funcall lang-from-sym major-mode))
nil))))
(defun eglot--guess-contact (&optional interactive)
"Helper for `eglot'.