From 79ffd285844bb8a97372c68dfa1dbcc269b89c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 6 Aug 2018 17:53:09 +0100 Subject: [PATCH] Per #63: Accept functions as entries in eglot-server-programs CONTACT in the (MAJOR-MODE . CONTACT) association in eglot-server-programs can now be a function of no arguments producing any value previously valid for contact. This is useful for servers who insist on requiring project-specific command-line invocations. * README.md (Installation and usage): Add entry for java-mode. * eglot.el (eglot-server-programs): Add entry for java-mode. (eglot-server-programs): CONTACT can be a fucntion of no arguments. (eglot--guess-contact, eglot--connect): Accept function CONTACTs. --- README.md | 2 ++ eglot.el | 49 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 860dda85..f836b7fd 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ for the language of your choice. Otherwise, it prompts you to enter one: * PHP's [php-language-server][php-language-server] * C/C++'s [cquery][cquery] * Haskell's [IDE engine][haskell-ide-engine] +* Java's [Eclipse JDT Language Server][eclipse-jdt] I'll add to this list as I test more servers. In the meantime you can customize `eglot-server-programs`: @@ -277,4 +278,5 @@ Under the hood: [solargraph]: https://github.com/castwide/solargraph [windows-subprocess-hang]: https://www.gnu.org/software/emacs/manual/html_node/efaq-w32/Subprocess-hang.html [haskell-ide-engine]: https://github.com/haskell/haskell-ide-engine +[eclipse-jdt]: https://github.com/eclipse/eclipse.jdt.ls diff --git a/eglot.el b/eglot.el index c3a0d518..d1e5c951 100644 --- a/eglot.el +++ b/eglot.el @@ -77,20 +77,36 @@ :prefix "eglot-" :group 'applications) -(defvar eglot-server-programs '((rust-mode . (eglot-rls "rls")) - (python-mode . ("pyls")) - ((js-mode - js2-mode - rjsx-mode) . ("javascript-typescript-stdio")) - (sh-mode . ("bash-language-server" "start")) - ((c++-mode - c-mode) . (eglot-cquery "cquery")) - (ruby-mode - . ("solargraph" "socket" "--port" - :autoport)) - (php-mode . ("php" "vendor/felixfbecker/\ +(defvar eglot-server-programs + `((rust-mode . (eglot-rls "rls")) + (python-mode . ("pyls")) + ((js-mode + js2-mode + rjsx-mode) . ("javascript-typescript-stdio")) + (sh-mode . ("bash-language-server" "start")) + ((c++-mode + c-mode) . (eglot-cquery "cquery")) + (ruby-mode + . ("solargraph" "socket" "--port" + :autoport)) + (php-mode . ("php" "vendor/felixfbecker/\ language-server/bin/php-language-server.php")) - (haskell-mode . ("hie-wrapper"))) + (haskell-mode . ("hie-wrapper")) + (java-mode + . ,(lambda () + `("java" + "-Declipse.application=org.eclipse.jdt.ls.core.id1" + "-Dosgi.bundles.defaultStartLevel=4" + "-Declipse.product=org.eclipse.jdt.ls.core.product" + "-Dlog.protocol=true" + "-Dlog.level=ALL" + "-noverify" + "-Xmx1G" + "-jar" "plugins/org.eclipse.equinox.launcher_1.5.100.v20180611-1436.jar" + "-configuration" "config_mac" + "-data" ,(if-let ((proj (project-current))) + (car (project-roots proj)) + default-directory))))) "How the command `eglot' guesses the server to start. An association list of (MAJOR-MODE . CONTACT) pairs. MAJOR-MODE is a mode symbol, or a list of mode symbols. The associated @@ -121,7 +137,10 @@ of those modes. CONTACT can be: converted to produce a plist with a suitable :PROCESS initarg to CLASS-NAME. The class `eglot-lsp-server' descends `jsonrpc-process-connection', which you should see for the - semantics of the mandatory :PROCESS argument.") + semantics of the mandatory :PROCESS argument. + +* A function of no arguments producing any of the above values + for CONTACT.") (defface eglot-mode-line '((t (:inherit font-lock-constant-face :weight bold))) @@ -310,6 +329,7 @@ be guessed." (lambda (m1 m2) (or (eq m1 m2) (and (listp m1) (memq m2 m1))))))) + (guess (if (functionp guess) (funcall guess) guess)) (class (or (and (consp guess) (symbolp (car guess)) (prog1 (car guess) (setq guess (cdr guess)))) 'eglot-lsp-server)) @@ -457,6 +477,7 @@ This docstring appeases checkdoc, that's all." (nickname (file-name-base (directory-file-name default-directory))) (readable-name (format "EGLOT (%s/%s)" nickname managed-major-mode)) autostart-inferior-process + (contact (if (functionp contact) (funcall contact) contact)) (initargs (cond ((keywordp (car contact)) contact) ((integerp (cadr contact))