/lsp-docker

Scripts and configurations to leverage lsp-mode in docker environment

Primary LanguageC#GNU General Public License v3.0GPL-3.0

Docker image + scripts for running lsp-mode in docker environment.

Table of Contents

Preconfigured language servers

The docker has the following content:

Usage

There are 3 supported modes:

docker standalone

Run emacs and language servers in the docker container.

Spacemacs

  • Clone spacemacs repo
# Clone spacemacs develop
git clone -b develop https://github.com/syl20bnr/spacemacs ~/.emacs.d-docker
  • Clone lsp-docker.
git clone https://github.com/emacs-lsp/lsp-docker
  • Run
    docker run -ti --rm -v $('pwd'):/mnt/workspace \
           -v /etc/localtime:/etc/localtime:ro \
           -v ~/.gnupg:${UHOME}/.gnupg \
           -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket \
           -v /tmp/.X11-unix:/tmp/.X11-unix \
           -v /etc/machine-id:/etc/machine-id:ro \
           -v ~/.emacs.d-docker/:/root/.emacs.d \
           -v $(pwd)/dotspacemacs.el:/root/.spacemacs \
           -v $(pwd)/demo-projects/:/Projects \
           -e DISPLAY=$DISPLAY \
           -e TZ=UA \
           yyoncho/lsp-emacs-docker emacs
        

Vanilla

Run
docker run -ti --rm -v $('pwd'):/mnt/workspace \
       -v /etc/localtime:/etc/localtime:ro \
       -v ~/.gnupg:${UHOME}/.gnupg \
       -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket \
       -v /tmp/.X11-unix:/tmp/.X11-unix \
       -v /etc/machine-id:/etc/machine-id:ro \
       -v $(pwd)/demo-projects/:/Projects \
       -v $(pwd)/emacs.d/:/root/.emacs.d \
       -e DISPLAY=$DISPLAY \
       -e TZ=UA \
       yyoncho/lsp-emacs-docker emacs

docker Language Server running over local sources (only Linux/MacOS)

In this mode, lsp-mode runs the Language Server in docker container over local sources.

Configuration

  • Clone repo.
git clone https://github.com/emacs-lsp/lsp-docker
  • add it to load path and register the docker clients(currently pyls and rls are supported, but adding other clients is trivial).
(with-eval-after-load 'lsp-clients
  (add-to-list 'load-path "<path-to-lsp-docker-dir>")
  (require 'lsp-docker)
  ;; register the clients
  (lsp-docker-init-default-clients
   :path-mappings '(("path-to-projects-you-want-to-use" . "/projects"))
   :docker-image-id "yyoncho/lsp-emacs-docker"
   :docker-container-name "lsp-container"
   :priority 2))

How it works

lsp-mode starts the image passed as :docker-image-id and mounts :path-mappings in the container. Then when the process is started lsp-mode translates the local paths to docker path and vice versa using the :path-mappings specified when calling lsp-docker-init-default-clients. You may use lsp-enabled-clients and lsp-disabled-clients to control what language server will be used to run for a particular project(refer to lsp-mode FAQ on how to configure .dir-locals).

docker over TRAMP (TBD)

Docker running the language servers and hosting the sources, Emacs running on the desktop machine and connecting to docker instance over TRAMP.

See also

  • docker - package for managing docker images/containers.