branch: externals/eglot commit a5b7b7d933b97db9ce5f8b7dcc8c866f7c35b220 Author: João Távora <joaotav...@gmail.com> Commit: João Távora <joaotav...@gmail.com>
Fix #688: Support multiple servers out-of-box for same mode Also per #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. --- NEWS.md | 6 ++++++ README.md | 5 +++-- eglot.el | 28 +++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 03a22bcc53..ec39654929 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # (upcoming) +##### Multiple servers supported out-of-box for same major mdoe ([#688][github#688]) + +In practice, this removes the need for Eglot to "officially" bless one +server over another. Thanks to Felicián Németh for the original idea. + ##### TRAMP support ([#637][github#637], ([#463][github#463], ([#84][github#84]) Thanks to Brian Cully for the minimalist approach. @@ -272,4 +277,5 @@ and now said bunch of references--> [github#637]: https://github.com/joaotavora/eglot/issues/637 [github#643]: https://github.com/joaotavora/eglot/issues/643 [github#686]: https://github.com/joaotavora/eglot/issues/686 +[github#688]: https://github.com/joaotavora/eglot/issues/688 [github#695]: https://github.com/joaotavora/eglot/issues/695 diff --git a/README.md b/README.md index e367b0fd97..ca78603474 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,12 @@ find-library` can help you tell if that happened. * Javascript's [TS & JS Language Server ][typescript-language-server] * Rust's [rls][rls] -* Python's [pyls][pyls] +* Python's [pylsp][pylsp] or [pyls][pyls] * Ruby's [solargraph][solargraph] * Java's [Eclipse JDT Language Server][eclipse-jdt] * Bash's [bash-language-server][bash-language-server] * PHP's [php-language-server][php-language-server] -* C/C++'s [ccls][ccls] ([cquery][cquery] and [clangd][clangd] also work) +* C/C++'s [clangd][clangd] or [ccls][ccls] * Haskell's [haskell-language-server][haskell-language-server] * Elm's [elm-language-server][elm-language-server] * Kotlin's [kotlin-language-server][kotlin-language-server] @@ -540,6 +540,7 @@ Under the hood: [lsp]: https://microsoft.github.io/language-server-protocol/ [rls]: https://github.com/rust-lang-nursery/rls [pyls]: https://github.com/palantir/python-language-server +[pylsp]: https://github.com/python-lsp/python-lsp-server [gnuelpa]: https://elpa.gnu.org/packages/eglot.html [melpa]: http://melpa.org/#/eglot [typescript-language-server]: https://github.com/theia-ide/typescript-language-server diff --git a/eglot.el b/eglot.el index 13d9952494..a739419e9d 100644 --- a/eglot.el +++ b/eglot.el @@ -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"))