Connect to lsp server on TCP


I have a docker container running pylsp --tcp --port 5007, and the port is exposed to the host. The container contains a Python source code (in a Docker volume) and the main goal is to run Mypy on it. mypy installed on the container, as well as python-lsp-server and pylsp-mypy. The code dependencies and stubs are installed too. The goal is that developers have nothing to setup, all is containerized and work the same for everyone.

Should I connect the LSP server with start_client on localhost:5007? Will it be as easy as vim.lsp.start to configure?

Thank a lot!

1 Like

Reading the doc twice, vim.lsp.start should work, passing vim.lsp.rpc.connect() as cmd?

Just discovered this doc Running language servers in containers · neovim/nvim-lspconfig Wiki · GitHub


Thank you for this. I was in the middle of my search and you saved me a bunch of time.

Nice to see I’m not alone :slight_smile:

Actually, I think I’ll will still run the lsp-server in a Docker container, but communicating on stdio rather that TCP. My first plan was to run the lsp-server container in background in our docker compose stack, but it’s easier if neovim start the the container on demand, and communicate on stdio.

I’m still trying (when I can find a moment…) to finalize settings like root_dir, workspace_folders, especially to:

  • start the container for a specific project, and for not related projects to start pylsp from the host as usual,
  • have the same project path on host and container, so that when the lsp client ask for somehting on /home/dfroger/mycode/, mypy in the container can actually find the file /home/dfroger/mycode/ Not sure if relative paths can be used here (would be great), or if I have to mount the absolute path in the docker volume.

And finally I’ll see how to configure the tools (mypy, black, linter) in the docker container rather than in editor conf, so that all the devs working on the project work with the same conf.