aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2024-08-07 12:51:16 +0100
committerJoão Távora2024-08-07 14:43:47 +0100
commit628f2bf579d958bcaddb66c0a58c1a21650d76af (patch)
tree3b85060a9ff965c976ead81c8911926193b98b27
parent2b087abdbb99fee2a670896fb34c666199e9ba84 (diff)
downloademacs-628f2bf579d958bcaddb66c0a58c1a21650d76af.tar.gz
emacs-628f2bf579d958bcaddb66c0a58c1a21650d76af.zip
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.
-rw-r--r--lisp/progmodes/eglot.el51
-rw-r--r--test/lisp/progmodes/eglot-tests.el4
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."
1238 "Lookup `eglot-server-programs' for MODE. 1238 "Lookup `eglot-server-programs' for MODE.
1239Return (LANGUAGES . CONTACT-PROXY). 1239Return (LANGUAGES . CONTACT-PROXY).
1240 1240
1241MANAGED-MODES is a list with MODE as its first element. 1241LANGUAGES is a list ((MANAGED-MODE . LANGUAGE-ID) ...). MANAGED-MODE is
1242Subsequent elements are other major modes also potentially 1242a major mode also potentially managed by the server that is to manage
1243managed by the server that is to manage MODE. 1243MODE. LANGUAGE-ID is string identifying the language to the LSP server.
1244 1244It's derived from the corresponding mode name, or explicitly specified
1245LANGUAGE-IDS is a list of the same length as MANAGED-MODES. Each 1245in `eglot-server-programs' (which see).
1246elem is derived from the corresponding mode name, if not
1247specified in `eglot-server-programs' (which see).
1248 1246
1249CONTACT-PROXY is the value of the corresponding 1247CONTACT-PROXY is the value of the corresponding
1250`eglot-server-programs' entry." 1248`eglot-server-programs' entry."
1251 (cl-flet ((languages (main-mode-sym specs) 1249 (cl-loop
1252 (let* ((res 1250 for (modes . contact) in eglot-server-programs
1253 (mapcar (jsonrpc-lambda (sym &key language-id &allow-other-keys) 1251 for llists = (mapcar #'eglot--ensure-list
1254 (cons sym 1252 (if (or (symbolp modes) (keywordp (cadr modes)))
1255 (or language-id 1253 (list modes) modes))
1256 (or (get sym 'eglot-language-id) 1254 for normalized = (mapcar (jsonrpc-lambda (sym &key language-id &allow-other-keys)
1257 (replace-regexp-in-string 1255 (cons sym
1258 "\\(?:-ts\\)?-mode$" "" 1256 (or language-id
1259 (symbol-name sym)))))) 1257 (or (get sym 'eglot-language-id)
1260 specs)) 1258 (replace-regexp-in-string
1261 (head (cl-find main-mode-sym res :key #'car))) 1259 "\\(?:-ts\\)?-mode$" ""
1262 (cons head (delq head res))))) 1260 (symbol-name sym))))))
1263 (cl-loop 1261 llists)
1264 for (modes . contact) in eglot-server-programs 1262 when (cl-some (lambda (cell)
1265 for specs = (mapcar #'eglot--ensure-list 1263 (provided-mode-derived-p mode (car cell)))
1266 (if (or (symbolp modes) (keywordp (cadr modes))) 1264 normalized)
1267 (list modes) modes)) 1265 return (cons normalized contact)))
1268 thereis (cl-some (lambda (spec)
1269 (cl-destructuring-bind (sym &key &allow-other-keys) spec
1270 (and (provided-mode-derived-p mode sym)
1271 (cons (languages sym specs) contact))))
1272 specs))))
1273 1266
1274(defun eglot--guess-contact (&optional interactive) 1267(defun eglot--guess-contact (&optional interactive)
1275 "Helper for `eglot'. 1268 "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
1235 (let ((eglot-server-programs '(((baz-mode (foo-mode :language-id "bar")) 1235 (let ((eglot-server-programs '(((baz-mode (foo-mode :language-id "bar"))
1236 . ("prog-executable"))))) 1236 . ("prog-executable")))))
1237 (eglot--guessing-contact (_ nil _ _ modes guessed-langs) 1237 (eglot--guessing-contact (_ nil _ _ modes guessed-langs)
1238 (should (equal guessed-langs '("bar" "baz"))) 1238 (should (equal guessed-langs '("baz" "bar")))
1239 (should (equal modes '(foo-mode baz-mode))))))) 1239 (should (equal modes '(baz-mode foo-mode)))))))
1240 1240
1241(defun eglot--glob-match (glob str) 1241(defun eglot--glob-match (glob str)
1242 (funcall (eglot--glob-compile glob t t) str)) 1242 (funcall (eglot--glob-compile glob t t) str))