Skip to content

Commit

Permalink
Per #63: Accept functions as entries in eglot-server-programs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joaotavora committed Aug 6, 2018
1 parent 2728e12 commit 79ffd28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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

49 changes: 35 additions & 14 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 79ffd28

Please sign in to comment.