Skip to content

Commit

Permalink
Fix joaotavora/eglot#688: Support multiple servers out-of-box for sam…
Browse files Browse the repository at this point in the history
…e mode

Also per joaotavora/eglot#537.

* eglot.el (eglot-alternatives): new helper.
(eglot-server-programs): Use it.  Use clangd and pylsp.

* NEWS.md: Mention feature.

* README.md (Connecting to a server): Mention pylsp and clangd.
  • Loading branch information
joaotavora committed May 22, 2021
1 parent f70015b commit 1de5b61
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,37 @@
:prefix "eglot-"
:group 'applications)

(defvar eglot-server-programs '((rust-mode . (eglot-rls "rls"))
(python-mode . ("pyls"))
(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 of one
argument."
(lambda (&optional interactive)
(let* ((listified (cl-loop for a in alternatives
collect (if (listp a) a (list a))))
(available (cl-remove-if-not #'executable-find listified :key #'car)))
(cond ((and interactive (cdr available))
(let ((chosen (completing-read
"[eglot] More than one server executable available:"
(mapcar #'car available)
nil t nil nil (car (car available)))))
(assoc chosen available #'equal)))
((car available))
(t
(car listified))))))

(defvar eglot-server-programs `((rust-mode . (eglot-rls "rls"))
(python-mode
. ,(eglot-alternatives '("pyls" "pylsp")))
((js-mode typescript-mode)
. ("typescript-language-server" "--stdio"))
(sh-mode . ("bash-language-server" "start"))
((php-mode phps-mode)
. ("php" "vendor/felixfbecker/\
language-server/bin/php-language-server.php"))
((c++-mode c-mode) . ("ccls"))
((c++-mode c-mode) . ,(eglot-alternatives
'("clangd" "ccls")))
(((caml-mode :language-id "ocaml")
(tuareg-mode :language-id "ocaml") reason-mode)
. ("ocamllsp"))
Expand Down

0 comments on commit 1de5b61

Please sign in to comment.