Function: eglot-alternatives
eglot-alternatives is a byte-compiled function defined in eglot.el.gz.
Signature
(eglot-alternatives ALTERNATIVES)
Documentation
Compute server-choosing function for eglot-server-programs.
Each element of ALTERNATIVES is a string PROGRAM or a list of strings (PROGRAM ARGS...) where program names an LSP server program to start with ARGS. Returns a function to be invoked automatically by Eglot on startup. When invoked, that function will return a list (ABSPATH ARGS), where ABSPATH is the absolute path of the PROGRAM that was chosen (interactively or automatically).
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defun eglot-alternatives (alternatives)
"Compute server-choosing function for `eglot-server-programs'.
Each element of ALTERNATIVES is a string PROGRAM or a list of
strings (PROGRAM ARGS...) where program names an LSP server
program to start with ARGS. Returns a function to be invoked
automatically by Eglot on startup. When invoked, that function
will return a list (ABSPATH ARGS), where ABSPATH is the absolute
path of the PROGRAM that was chosen (interactively or
automatically)."
(lambda (&optional interactive _project)
;; JT@2021-06-13: This function is way more complicated than it
;; could be because it accounts for the fact that
;; `eglot--executable-find' may take much longer to execute on
;; remote files.
(let* ((listified (cl-loop for a in alternatives
collect (if (listp a) a (list a))))
(err (lambda ()
(error "None of '%s' are valid executables"
(mapconcat #'car listified ", ")))))
(cond ((and interactive current-prefix-arg)
;; A C-u always lets user input something manually,
nil)
(interactive
(let* ((augmented (mapcar (lambda (a)
(let ((found (eglot--executable-find
(car a) t)))
(and found
(cons (car a) (cons found (cdr a))))))
listified))
(available (remove nil augmented)))
(cond ((cdr available)
(cdr (assoc
(completing-read
"[eglot] More than one server executable available: "
(mapcar #'car available)
nil t nil nil (car (car available)))
available #'equal)))
((cdr (car available)))
(t
;; Don't error when used interactively, let the
;; Eglot prompt the user for alternative (github#719)
nil))))
(t
(cl-loop for (p . args) in listified
for probe = (eglot--executable-find p t)
when probe return (cons probe args)
finally (funcall err)))))))