2

I am developing directly on a development container in a container on a (remote) Kubernetes cluster. The container has an ssh-server which means that eglot can start the remote lsp-server through ssh.

Additionally I've set up port-forwarding to forward a port on the local machine to the lsp-server port on the container. In this way eglot can connect to the lsp-server through a port on my localhost.

However I am not able to find the correct commands to automatically make eglot start the lsp-server remotely and subsequently connect to the server on a local port.

With the following command added tot the eglot-server-programs I can get eglot to start the remote lsp-server (by running M-x eglot). (PS I run this command after I have opened a file on the remote container through tramp, eglot seems to find out automatically that the command to start the lsp-server should be run on the remote host).

(add-to-list 'eglot-server-programs '((python-mode python-ts-mode) "pylsp" "--tcp" "--host=0.0.0.0" "--port" "5007")) 

When subsequently I add the following to the eglot-server-programs and run M-x eglot again:

(add-to-list 'eglot-server-programs '((python-mode python-ts-mode) "localhost" 5007)) 

Then eglot seems to connect to the server and things seem to work fine.

But again, I cannot get eglot to perform the two steps above automatically. Is there a way to make eglot preform both steps above by adding only a single entry to the 'eglot-server-programs list?

Or maybe there are two separate commands that I can run to first start the remote-lsp server and subsequently to connect to the server though the local port?

1 Answer 1

0

Is that not the exact case catered for here?

* A list (PROGRAM [ARGS...] :autoport [MOREARGS...]), whereupon a combination of previous options is used. First, an attempt is made to find an available server port, then PROGRAM is launched with ARGS; the ‘:autoport’ keyword substituted for that number; and MOREARGS. Eglot then attempts to establish a TCP connection to that port number on the localhost. 

(n.b. I might be misunderstanding, and I have no experience with this approach.)

1
  • First of all thank you for looking into this. But as I understand the method above determines a free port on the remote host dynamically and subsequently tries to connect to the selected free port number. However, I'm setting up a port forward in advance on a specific port on my local system. Therefore I would like to specify the exact port number to use in the above command instead of having eglot determining a free port dynamically. Also, preferably, I would like to be able to select different port numbers for the LSP server and for the locally forwarded port. Commented Sep 15, 2024 at 19:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.