Configuring eglot to use docker containers
- François
I recently wanted to use LSP on emacs. The next version of emacs, 29 at time of writing, will include eglot. So I wanted to give it a try.
As I run my development tools on docker containers, my requirement was to be able to run the language servers in docker.
After some back and forth, I found the following configuration suitable for me.
I created a file lsp-docker.sh
to encapsulate the basic command line to start the docker container:
#!/bin/bash
exec docker run --rm --interactive --volume ~francois/dev:~francois/dev $@
And in the .emacs
file, I configured the following:
;; See https://github.com/joaotavora/eglot/blob/28c1c3a52e1cb7fa7260815eb53700f348d48dd5/eglot.el#L402-L404
(setq eglot-withhold-process-id "1")
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs `(elixir-mode . ("~francois/.emacs.d/lsp-docker.sh" "metio/devcontainers-elixir" "/opt/elixir/ls/language_server.sh")))
(add-to-list 'eglot-server-programs `(go-mode . ("~francois/.emacs.d/lsp-docker.sh" "metio/devcontainers-go" "gopls" "serve")))
(add-to-list 'eglot-server-programs `(js-mode . ("~francois/.emacs.d/lsp-docker.sh" "metio/devcontainers-nodejs" "typescript-language-server --stdio")))
)
This configuration should be great starting point to add more languages.
Have a comment? Contact me by email.