From: João Távora Date: Wed, 7 Aug 2024 11:51:16 +0000 (+0100) Subject: Eglot: simplify eglot--lookup-mode X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d02932d8ffe48fd9e7d6ce25df07836ab2e1c323;p=emacs.git Eglot: simplify eglot--lookup-mode No longer reorder the LANGUAGES return value to have the originating mode upfront, since it doesn't seem to serve any practical purpose anymore. bug#72343 * lisp/progmodes/eglot.el (eglot--lookup-mode): Simplify. * test/lisp/progmodes/eglot-tests.el (eglot-test-server-programs-guess-lang): Adjust. (cherry picked from commit 628f2bf579d958bcaddb66c0a58c1a21650d76af) --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index b57cfe260e1..f71ab3c6588 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1238,38 +1238,31 @@ PRESERVE-BUFFERS as in `eglot-shutdown', which see." "Lookup `eglot-server-programs' for MODE. Return (LANGUAGES . CONTACT-PROXY). -MANAGED-MODES is a list with MODE as its first element. -Subsequent elements are other major modes also potentially -managed by the server that is to manage MODE. - -LANGUAGE-IDS is a list of the same length as MANAGED-MODES. Each -elem is derived from the corresponding mode name, if not -specified in `eglot-server-programs' (which see). +LANGUAGES is a list ((MANAGED-MODE . LANGUAGE-ID) ...). MANAGED-MODE is +a major mode also potentially managed by the server that is to manage +MODE. LANGUAGE-ID is string identifying the language to the LSP server. +It's derived from the corresponding mode name, or explicitly specified +in `eglot-server-programs' (which see). CONTACT-PROXY is the value of the corresponding `eglot-server-programs' entry." - (cl-flet ((languages (main-mode-sym specs) - (let* ((res - (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)))))) - specs)) - (head (cl-find main-mode-sym res :key #'car))) - (cons head (delq head res))))) - (cl-loop - for (modes . contact) in eglot-server-programs - for specs = (mapcar #'eglot--ensure-list - (if (or (symbolp modes) (keywordp (cadr modes))) - (list modes) modes)) - thereis (cl-some (lambda (spec) - (cl-destructuring-bind (sym &key &allow-other-keys) spec - (and (provided-mode-derived-p mode sym) - (cons (languages sym specs) contact)))) - specs)))) + (cl-loop + for (modes . contact) in eglot-server-programs + for llists = (mapcar #'eglot--ensure-list + (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)))))) + llists) + when (cl-some (lambda (cell) + (provided-mode-derived-p mode (car cell))) + normalized) + return (cons normalized contact))) (defun eglot--guess-contact (&optional interactive) "Helper for `eglot'. diff --git a/test/lisp/progmodes/eglot-tests.el b/test/lisp/progmodes/eglot-tests.el index 1e653716a2c..534c47b2646 100644 --- a/test/lisp/progmodes/eglot-tests.el +++ b/test/lisp/progmodes/eglot-tests.el @@ -1235,8 +1235,8 @@ GUESSED-MAJOR-MODES-SYM are bound to the useful return values of (let ((eglot-server-programs '(((baz-mode (foo-mode :language-id "bar")) . ("prog-executable"))))) (eglot--guessing-contact (_ nil _ _ modes guessed-langs) - (should (equal guessed-langs '("bar" "baz"))) - (should (equal modes '(foo-mode baz-mode))))))) + (should (equal guessed-langs '("baz" "bar"))) + (should (equal modes '(baz-mode foo-mode))))))) (defun eglot--glob-match (glob str) (funcall (eglot--glob-compile glob t t) str))