Lsp-mode: Documentation incorrectly describes docker remote setup

Created on 3 Jul 2020  Â·  3Comments  Â·  Source: emacs-lsp/lsp-mode

Describe the bug

The current documentation contains the following note that describes how to register a new remote client (https://emacs-lsp.github.io/lsp-mode/page/remote/#sample-configuration):

Note: the path passed to lsp-tramp-connection should be either full path including host name, e. g. /docker:my-image:/usr/bin/rust-analyzer or the binary name (e. g. rust-analyzer) if the binary is on the path.

However if I specify the full path to the remote binary including the tramp prefix /docker:my-image: then lsp-mode is unable to find the language server binary. Specifying just the binary name that is on the container's path, i.e. pyls, works.

To Reproduce
Build an image that contains the language server from the following Dockerfile with the command docker build -t pyls .:

FROM python:3.8-buster

RUN pip3 install 'python-language-server[all]'

Next, run the container and mount some source code into its /app directory.

docker run -it -d -v /path/to/source:/app pyls bash

In emacs, open a source file called test.py with tramp assuming a docker container ID of 9a291afa6b31:

(C-x C-f) /docker:9a291afa6b31:/app/test.py

Enable lsp-mode in the tramp buffer:

(M-x) lsp-mode

Evaluate the following elisp in emacs:

(lsp-register-client
    (make-lsp-client :new-connection (lsp-tramp-connection "/docker:9a291afa6b31:/usr/local/bin/pyls")
                     :major-modes '(python-mode)
                     :remote? t
                     :server-id 'pyls-remote))

Finally, in the tramp buffer for test.py launch lsp:

(M-x) lsp

The mini-buffer will say the following:

Server pyls-remote:6112 status:starting exited with status exit. Do you want to restart it? (y or n)

The **Messages** buffer says:

Tramp: Opening connection for 9a291afa6b31 using docker...
Tramp: Sending command ‘exec docker  exec -it  9a291afa6b31 sh’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘9a291afa6b31’
Tramp: Opening connection for 9a291afa6b31 using docker...done
LSP :: Connected to [pyls-remote:6112 status:starting].
LSP :: pyls-remote has exited (exited abnormally with code 127)

If I change the argument to lsp-tramp-connection from "/docker:9a291afa6b31:/usr/local/bin/pyls" to "pyls", then everything works as expected.

Expected behavior
I expect that lsp-mode correctly finds the language server binary inside the container and runs without problems.

Which Language Server did you use
pyls inside Docker

OS
Linux Ubuntu 18.04

Error callstack
*lsp-log*

Command "/docker:9a291afa6b31:/usr/local/bin/pyls" is present on the path.
Command "/docker:9a291afa6b31:/usr/local/bin/pyls" is present on the path.
Found the following clients for /docker:9a291afa6b31:/app/lsp.py: (server-id pyls-remote, priority 0)
The following clients were selected based on priority: (server-id pyls-remote, priority 0)

Most helpful comment

@kmdouglass is right, I will update the docs according to the latest guidance by Michael Albinus.

All 3 comments

I think that just pyls works because docker creates a network dns local with the name of the container, pyls in the case, I'm not familiar with using /docker:9a291afa6b31:/usr/local/bin/pyls, maybe @yyoncho may have more context about it?

@kmdouglass is right, I will update the docs according to the latest guidance by Michael Albinus.

Pushed a fix. In general, I recommend you to use lsp-docker over tramp. It works better and the benefit is that you can use local tools over the source code(or at least, AFAIK projectile and related work better on local source code)

Was this page helpful?
0 / 5 - 0 ratings