emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 628f2bf579d 1/2: Eglot: simplify eglot--lookup-mode


From: João Távora
Subject: master 628f2bf579d 1/2: Eglot: simplify eglot--lookup-mode
Date: Wed, 7 Aug 2024 09:45:13 -0400 (EDT)

branch: master
commit 628f2bf579d958bcaddb66c0a58c1a21650d76af
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    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.
---
 lisp/progmodes/eglot.el            | 51 ++++++++++++++++----------------------
 test/lisp/progmodes/eglot-tests.el |  4 +--
 2 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 31948a12d69..44117fe7a01 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]