Giter Site home page Giter Site logo

emacs-lsp / lsp-docker Goto Github PK

View Code? Open in Web Editor NEW
238.0 15.0 34.0 6.2 MB

Scripts and configurations to leverage lsp-mode in docker environment

License: GNU General Public License v3.0

Dockerfile 3.80% Emacs Lisp 89.84% Shell 2.90% C++ 0.51% TypeScript 0.28% Python 0.37% JavaScript 0.29% CSS 0.93% HTML 0.19% Go 0.27% SCSS 0.16% Makefile 0.46%
docker lsp-mode starter-kit

lsp-docker's Introduction

lsp-mode uses lsp-docker to run language servers using in containers

./images/logo.png

Table of Contents

Preconfigured language servers

emacslsp/lsp-docker-langservers has the following content:

Usage

There are two ways of working with containerized language servers:

emacslsp/lsp-docker-langservers

This container is used by lsp-docker to run Language Servers for lsp-mode over local sources. You must pull the container before lsp-docker can use it

Configuration

  • Clone the repo
    git clone https://github.com/emacs-lsp/lsp-docker
        
  • Pull the container
    docker pull emacslsp/lsp-docker-langservers
        
  • Add repo to load path and register the docker clients in your ~/.emacs file
    ;; Uncomment the next line if you are using this from source
    ;; (add-to-list 'load-path "<path-to-lsp-docker-dir>")
    (require 'lsp-docker)
    
    (defvar lsp-docker-client-packages
        '(lsp-css lsp-clients lsp-bash lsp-go lsp-pylsp lsp-html lsp-typescript
          lsp-terraform lsp-clangd))
    
    (setq lsp-docker-client-configs
        '((:server-id bash-ls :docker-server-id bashls-docker :server-command "bash-language-server start")
          (:server-id clangd :docker-server-id clangd-docker :server-command "clangd")
          (:server-id css-ls :docker-server-id cssls-docker :server-command "css-languageserver --stdio")
          (:server-id dockerfile-ls :docker-server-id dockerfilels-docker :server-command "docker-langserver --stdio")
          (:server-id gopls :docker-server-id gopls-docker :server-command "gopls")
          (:server-id html-ls :docker-server-id htmls-docker :server-command "html-languageserver --stdio")
          (:server-id pylsp :docker-server-id pyls-docker :server-command "pylsp")
          (:server-id ts-ls :docker-server-id tsls-docker :server-command "typescript-language-server --stdio")))
    
    (require 'lsp-docker)
    (lsp-docker-init-clients
      :path-mappings '(("path-to-projects-you-want-to-use" . "/projects"))
      :client-packages lsp-docker-client-packages
      :client-configs lsp-docker-client-configs)
        

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).

emacslsp/lsp-docker-full

The container emacslsp/lsp-docker-full contains:

  • The above language servers
  • Emacs28 compiled with native JSON support for better performance.

Flags

FlagPurposeDefault
EMACS_D_VOLUMEEmacs folder to use for /root/.emacsEmacs: $(pwd)/emacs.d Spacemacs: $(pwd)/spacemacs
PROJECTS_VOLUMEDirectory to mount at /Projects$(pwd)/demo-projects/
TZTimezone to user in containerEurope/Minsk
DOCKER_FLAGSAny additional docker flagsN/A

Emacs

  • Clone lsp-docker.
    git clone https://github.com/emacs-lsp/lsp-docker
    cd lsp-docker
        
  • Run
    bash start-emacs.sh
        

Spacemacs

  • Clone lsp-docker.
    git clone https://github.com/emacs-lsp/lsp-docker
    cd lsp-docker
        
  • Clone spacemacs repo
    # Clone spacemacs develop
    git clone -b develop https://github.com/syl20bnr/spacemacs spacemacs
        
  • Run
    EMACS_D_VOLUME=/path/to/spacemacs bash start-spacemacs.sh
        

Custom language server containers

You can use manually built language containers or images hosting language server(s), just follow a few simple rules (shown below). The docker images may feature an optional tag, if omitted latest will be assumed.

Building a container (or an image) manually:

You have 2 constraints:

  • A language server must be launched in stdio mode (other types of communication are yet to be supported)
  • A docker container (only container subtype, see the configuration below) must have your language server as an entrypoint (basically you have to be able to launch it with docker start -i <container_name> as it is launched this way with lsp-docker)

When you have sucessfully built a language server, you have to register it with either a configuration file or a .dir-locals file.

Registering a language server using a persistent configuration file:

A configuration file is a yaml file that can be located at:

<PROJECT_ROOT>/.lsp-docker.yml
<PROJECT_ROOT>/.lsp-docker.yaml
<PROJECT_ROOT>/.lsp-docker/.lsp-docker.yml
<PROJECT_ROOT>/.lsp-docker/.lsp-docker.yaml
<PROJECT_ROOT>/.lsp-docker/lsp-docker.yml
<PROJECT_ROOT>/.lsp-docker/lsp-docker.yaml
<PROJECT_ROOT>/.lsp-docker/config.yml
<PROJECT_ROOT>/.lsp-docker/config.yaml

It is structured in the following way:

# single server configuration
lsp:
  server:
    type: docker
    # subtype:
    # - "container": attach to an already running container
    # - "image": when image does not exist, try to build it based on the dockerfile found in the project-scope
    #   (see Automatic image building). An image might feature an optional tag, i.e. '<image>:<tag>'. If a
    #   tagless image is indicated 'latest' will be assumed.
    subtype: container
    # Image/container name to use for this language server.
    name: image-container-name
    # server id of a registered LSP server. You can find the list of registered servers evaluating:
    #
    # `(ht-keys lsp-clients)`
    #
    # source:
    # https://stackoverflow.com/questions/17066169/retrieve-keys-from-hash-table-sorted-by-the-values-efficiently
    server: server-id-of-the-base-server
    # an (optional) array of parameters (docker or podman) to launch the image with
    # initially intended to host the '--userns' parameter
    # NOTE: 'launch_parameters' are not used with 'container' subtype servers
    # in this case embed all required parameters when creating the server instead
    launch_parameters:
      - "--userns=nomap"
    # command to launch the language server in stdio mode
    # NOTE: 'launch_command' is not used with 'container' subtype servers as a command is embedded in a
    # container itself and serves as entrypoint
    launch_command: "launch command with arguments"
  mappings:
    # NOTE: the paths must be within the project this server is being build for
    - source: "/your/host/source/path"
      destination: "/your/path/inside/the/container"

# multiple server configuration
lsp:
  server:
    - type: ...
      subtype: ...
      ...                       # keys as in the classic single server case, e.g. type, subtype, etc...
    - ...                       # other single server configuration(s)
  mappings:                     # shared among all servers
    - source: <path-on-host>
      destination: <path-on-lang-server>
    ...                         # other mappings

Registering a language server using a .dir-locals file:

Just refer to the source code and general conventions of using .dir-locals. The variable you need is lsp-docker-persistent-default-config, its content is merged with the lsp section from a configuration file (if present).

Automatic image building:

You can also build an image automatically (currently supported only for image subtype): just drop the corresponding Dockerfile into the .lsp-docker folder in the project root (Dockerfile may be named as Dockerfile or Dockerfile.lsp). Building process is triggered by the lsp-docker-register call (you will be prompted whether you want to build the image). Image building takes place in the project root (not in the .lsp-docker subfolder)! In case of an automatic build the image will be registered automatically (based on the values from the config or .dir-locals file).

You can also troubleshoot any issues with supplemental docker calls (checking whether the required image already exists, building a new image) using the supplemental logging functionality: there are 2 variables: first you have to set lsp-docker-log-docker-supplemental-calls to true-like value (by default it is nil) and then specify the log buffer in the lsp-docker-log-docker-supplemental-calls-buffer-name variable (by default it is set to *lsp-docker-supplemental-calls*)

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.

Maintainers

lsp-docker's People

Contributors

ahonnecke avatar aidalgol avatar bjodah avatar dependabot[bot] avatar ericdallo avatar factyy avatar hotoku avatar jcs090218 avatar jinnovation avatar nicber avatar rnikoopour avatar sfavazza avatar sfavazza-duagon avatar spearalot avatar thatnerdjosh avatar vidbina avatar yyoncho avatar zflat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lsp-docker's Issues

Spacemacs Installation with custom docker image?

I'm confused, how do I install this properly for spacemacs and how do I use this with a different docker instance? Do I have to use start-spacemacs.sh? Or do I launch spacemacs on the host machine and open the project and lsp-docker automates it?

file mode specification error invalid-read-syntax

Hello! I updated my emacs via elpa and melpa (packages-list) and I updated all of my packages. When I open up a file for a programming language, my LSP triggers and I receive this error.

file mode specification error invalid-read-syntax

Digging through the messages. It appears that this comes from lsp-docker.el. There might be an extra closing paren somewhere?

Issue evaluating hashtable on default mappings config

I was having trouble registering a custom image/dockerfile as an LSP server following the GitHub readme...

After about 5h of debugging, I found out the issue was because I was happy with the default mappings and tried using them.

There is some issue where the hashtable in the list of mappings (below) is not evaluated:

(defcustom lsp-docker-persistent-default-config
  (ht ('server (ht ('type "docker")
                   ('subtype "image")
                   ('name "emacslsp/lsp-docker-langservers")
                   ('server nil)
                   ('launch_command nil)))
      ('mappings [
                  (ht ('source ".")
                      ('destination "/projects"))
                  ]))
  "Default configuration for all language servers with persistent configurations"
  :type 'hash-table
  :group 'lsp-docker
)

This is seen when printing the hashtable via an interactive function:

#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (server #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (launch_command "blah" server "custom-lsp" name "custom-lsp" subtype "image" type "docker")) mappings [(ht ('source ".") ('destination "/projects"))]))

I would fix this, but it may be quicker for you, as I am not experienced with development of elisp plugins.

If you can point me in the right direction for setting up my environment to work on an elisp plugin, I can fix it and create a PR.

docker tramp not work

Warning (lsp-mode): Failed to process xref entry for filename ’/docker:clangd:/opt/rh/devtoolset-8/root/usr/include/c++/8/memory’: Tramp failed to connect. If this happens repeatedly, try ‘M-x tramp-cleanup-this-connection’

actually, docker name is clangd-1 with suffix

Docker and lsp-mode?

I discovered this repository while trying to dockerize my language servers for lsp-mode. Sadly it doesn't support the ones I use. But I have some thoughts/findings/suggestions.

First off, from my point of view it would be nice if lsp-mode would just use containers for language servers. Around here we've already moved all development into containers, and doing the same for language servers would get around issues around language versions and, for instance, having to have a node environment available in order to use the Dockerfile language server. But I understand this would probably be met with some opposition.

Next best, again, in my opinion, would be if lsp-mode supplied docker images for all the language servers it supported, and could just run those as an alternative to installing it.

In my own mucking about I've found that it's pretty simple to make lsp-mode use a langage server in docker. I've just fixed the server configuration to point at a script that mounts in root directory at the same location in the docker image and then run the same command that lsp-mode would. For TCP based language servers one just have to bind the port with the -p switch to docker (and ensure that the server accepts connections from non-localhost).

Add support to pylsp

I get some warnings about pyls being deprecated:

Warning (emacs): The palantir python-language-server (pyls) is unmaintained; a maintained fork is the python-lsp-server (pylsp) project; you can install it with pip via: pip install python-lsp-server Disable showing Disable logging

It would be nice to add support to the pylsp server as well, so far I got it working with:

(use-package lsp-docker
  :straight t
  :config
  (defvar lsp-docker-client-packages
    '(lsp-css lsp-clients lsp-bash lsp-go lsp-html lsp-pylsp ;; lsp-pyls
	      lsp-dockerfile lsp-javascript lsp-terraform))

  (setq lsp-docker-client-configs
	'((:server-id bash-ls :docker-server-id bashls-docker :server-command "bash-language-server start")
	  (:server-id css-ls :docker-server-id cssls-docker :server-command "css-languageserver --stdio")
	  (:server-id dockerfile-ls :docker-server-id dockerfilels-docker :server-command "docker-langserver --stdio")
	  (:server-id gopls :docker-server-id gopls-docker :server-command "gopls")
	  (:server-id html-ls :docker-server-id htmls-docker :server-command "html-languageserver --stdio")
	  ;; (:server-id pyls :docker-server-id pyls-docker :server-command "pyls")
	  (:server-id pylsp :docker-server-id pylsp-docker :server-command "pylsp" :docker-image-id "martini97/lsp-docker-langservers" :docker-container-name "martini97-lsp-pylsp")
	  (:server-id ts-ls :docker-server-id tsls-docker :server-command "typescript-language-server --stdio")))

  (let ((projects-dir (expand-file-name "~/Projects")))
    (lsp-docker-init-clients
      :path-mappings `((,projects-dir . "/projects"))
      :client-packages lsp-docker-client-packages
      :client-configs lsp-docker-client-configs)))

On my Emacs config and using this Docker image:

# Local Variables:
# docker-image-name: "martini97/lsp-docker-langservers"
# End:

FROM emacslsp/lsp-docker-langservers

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

But it would be nice to have it added to the package.

Sample configuration for `lsp-docker-client-configs` is wrong.

In the README.org, the following snippet is offered as sample configuration for lsp-docker-client-configs.

      (setq lsp-docker-client-configs
          '((:server-id 'bash-ls :docker-server-id 'bashls-docker :server-command "bash-language-server start")
            (:server-id 'clangd :docker-server-id 'clangd-docker :server-command "clangd")
            (:server-id 'css-ls :docker-server-id 'cssls-docker :server-command "css-languageserver --stdio")
            (:server-id 'dockerfile-ls :docker-server-id 'dockerfilels-docker :server-command "docker-langserver --stdio")
            (:server-id 'gopls :docker-server-id 'gopls-docker :server-command "gopls")
            (:server-id 'html-ls :docker-server-id 'htmls-docker :server-command "html-languageserver --stdio")
            (:server-id 'pyls :docker-server-id 'pyls-docker :server-command "pyls")
            (:server-id 'ts-ls :docker-server-id 'tsls-docker :server-command "typescript-language-server --stdio")))

In this code, quote ' is duplicated. I think it should be as following

      (setq lsp-docker-client-configs
          '((:server-id bash-ls :docker-server-id bashls-docker :server-command "bash-language-server start")
            (:server-id clangd :docker-server-id clangd-docker :server-command "clangd")
            (:server-id css-ls :docker-server-id cssls-docker :server-command "css-languageserver --stdio")
            (:server-id dockerfile-ls :docker-server-id dockerfilels-docker :server-command "docker-langserver --stdio")
            (:server-id gopls :docker-server-id gopls-docker :server-command "gopls")
            (:server-id html-ls :docker-server-id htmls-docker :server-command "html-languageserver --stdio")
            (:server-id pyls :docker-server-id pyls-docker :server-command "pyls")
            (:server-id ts-ls :docker-server-id tsls-docker :server-command "typescript-language-server --stdio")))

Note the changes like :server-id 'bash-ls -> :server-id bash-ls and :docker-server-id 'bashls-docker -> :docker-server-id bashls-docker, and so on.

Use with other language-servers

Hello,

I tried to work through the documentation, but unfortunately, as elisp isn't my strong suite, I was unable to find the answers myself.

Is it possible, given that i create my own container, that I add additional language server to use? I'd like to use the php-language-server, which itself requires composer. Creating a Dockerfile which sets that up doesn't sound too hard, but I don't know where to go from there.

Could you help me with an example? I'd appreciate it.

Cheers.

Add ability to define docker lsp clients only for certain paths

I have started using lsp-docker with elixir-ls along with elixir under docker so that I can use whichever version of the LS I need for a given Elixir project. But now that I have started another Elixir project using my system's Elixir version (instead of via docker), I have discovered that my elixir-ls docker client is taking precedence over the client defined in the lsp-elixir elisp package.

The lsp-related part of my init:

;; Set up LSP Docker
(add-to-list 'load-path "~/src/elisp/lsp-docker")
(load-library "lsp-docker")

(with-eval-after-load "lsp-elixir"
  (lsp-docker-init-clients
   :path-mappings '(("/home/aidan/src" . "/projects"))
   :client-configs '((:server-id elixir-ls
                      ;;:priority -5
                      :docker-server-id elixirls-docker:1-10
                      :docker-image-id "elixir-ls:1.10"
                      :docker-container-name "lsp-elixir-container"
                      :server-command "language_server.sh"))))

;; Specify which projects should use which LSP clients.
(dir-locals-set-class-variables 'elixirls-docker:1-10
  '((nil . ((lsp-enabled-clients . (elixirls-docker:1-10))
            (eval . (add-hook 'elixir-mode-hook #'lsp))))))

(dir-locals-set-directory-class
 "/home/aidan/src/junk" 'elixirls-docker:1-10)

On discord, @yyoncho proposed adding the ability to specify an lsp-docker client only for certain paths.

Error running timer after update of lsp-docker to latest commit

Describe the Bug

lsp-docker became unusable for me after the changes introduced by commit c94531f yielding the following error message in *Messages*: Error running timer: (user-error "The path /home/dmrauh/Code is not under path mappings") after starting doom-emacs and opening a Python file.

To Reproduce

  • Use this configuration as part of a private config in doom-emacs
(load! "lsp-docker/lsp-docker")

(use-package! lsp-docker
  :after lsp-mode
  :config
  (setq lsp-docker-client-packages
        '(lsp-bash lsp-pyls))

  (setq lsp-docker-client-configs
        (list
         (list :server-id 'bash-ls :docker-server-id 'bashls-docker :server-command "bash-language-server start")
         (list :server-id 'pyls :docker-server-id 'pyls-docker :server-command "pyls")))

  (setq lsp-docker-path-mappings
        `((,(file-truename "~/Code") . "/Code")))

  (lsp-docker-init-clients
   :client-packages lsp-docker-client-packages
   :client-configs lsp-docker-client-configs
   :path-mappings lsp-docker-path-mappings))
  • Start doom-emacs
  • Open a Python file located in ~/Code

Expected Behavior
lsp-docker starting pyls in a docker container using the paths provided by path-mappings

Going back to the second to last commit by issuing git checkout HEAD~1 in the lsp-docker project directory makes everything work as expected again.

Updated Dockerfile based on Ubuntu 21.04. plus a helper script.

Thank you for creating and maintaining the lsp-docker project.

I was looking at the project's Docker Hub images, and on noting their age, I looked at the Dockerfiles for each. I thought given the age of the distribution in use (Ubuntu 18.04), that the used products/packages are likely in the latest LTS version of Ubuntu (21.04).

So, I have created an updated Dockerfile using packages for all code built from a git repo (ccls, clangd, golang), but keeping the local build of Go, Node and Python language servers.

Additionally, I created a script (which could be included in the built container, if desired), that shows the installation location of each language server, and it's version (where I could determine that information)

Run on the existing Docker Hub Container images, gives:

docker run "emacslsp/lsp-docker-langservers" bash -c "$(cat ShowInstalledAndVersion.sh)"

gopls                       : /root/go/bin/gopls                         : version master, built in $GOPATH mode 
ccls                        : /usr/bin/ccls                              : ccls version <unknown> clang version 8.0.0 (tags/RELEASE_800/final) 
bash-language-server        : /usr/local/bin/bash-language-server        : Version is 1.17.0 
css-languageserver          : /usr/local/bin/css-languageserver          : UNKNOWN
docker-langserver           : /usr/local/bin/docker-langserver           : UNKNOWN
html-languageserver         : /usr/local/bin/html-languageserver         : UNKNOWN
pyls                        : /usr/local/bin/pyls                        : UNKNOWN
typescript-language-server  : /usr/local/bin/typescript-language-server  : 0.4.0

Run on the container created by the provided Dockerfile, gives:

docker run "${EMACS_LSP_TAG}" bash -c "$(cat ShowInstalledAndVersion.sh)"

gopls                       : /root/go/bin/gopls                         : golang.org/x/tools/gopls master  golang.org/x/tools/[email protected] h1:Lru57ht8vtDMouRskFC085VAjBAZRAISd/lwvwOOV0Q= 
ccls                        : /usr/bin/ccls                              : Ubuntu ccls version 0.20210330-1 clang version 12.0.0-3ubuntu1~21.04.2 
bash-language-server        : /usr/local/bin/bash-language-server        : Version is 2.0.0 
css-languageserver          : /usr/local/bin/css-languageserver          : UNKNOWN
docker-langserver           : /usr/local/bin/docker-langserver           : UNKNOWN
html-languageserver         : /usr/local/bin/html-languageserver         : UNKNOWN
pyls                        : /usr/local/bin/pyls                        : UNKNOWN
typescript-language-server  : /usr/local/bin/typescript-language-server  : 0.7.1 

As the container lsp-docker-langservers is the most important for the project, I have worked on and attached that. But in looking at the other Dockerfile (lsp-docker-full), I noted that it builds Emacs from git, and additionally that the Docker Hub image for this Dockerfile is stated as being two years old. For testing lsp-docker, I was using Emacs 26.1 on CentOS 8.4 and had no issues — so maybe that Dockerfile, could use the vendor package version of Emacs from Ubuntu 21.04 — just a thought.

The attached Dockerfile has some possible TODOs, which you can review/action/delete as you see fit.

Formally: I am the sole author of the attached script, and authored the modifications in the attached Dockerfile. I donate the two attached files to the lsp-docker project and/or its user community under the project's current license the GNU General Public License v3.0. The Dockerfile is a derived work, so immediately is licensed by the GPLv3.0. I also permit without further interaction with myself, that my contributions may be re-licenced to GNU General Public License v3.0 or later, should the current or future maintainers wish to do so.

I hope this contribution meets with your approval or benefits the lsp-docker community,
Peter Bray
Sydney, Australia

Dockerfile.txt
ShowInstalledAndVersion.sh.txt

DAP: debug server support

When consulting the dap-mode official page, lsp-docker is mentioned as solution to dockerize a debug servers.

Though in the source code I cannot find any mention of the debug keyword. Is the support being dropped or never been there?

Questions: Find definition from libraries installed in container

It seems like we are not able to jump to definitions where the source codes are installed as libraries in the docker container. For example, jump to native python libraries.

I'm not sure how to make this happen. So I tried to open emacs in the docker container with emacslsp/lsp-docker-full, then of course, we could jump to that definition.

But I got another question. How to start emacs as gui from docker? There must some command line args that I don't know and I need to pass to enable gui...

So sum up the two question:

  1. Can I open emacs on desktop and use lsp-docker to find definitions from the libraries installed in the docker container?
  2. Can we open emacs from docker in gui?

I have a minimal test repo over here which contains the minimal reproduce steps https://github.com/ztlevi/lsp-docker-test

Unable to get setup working with Emacs 29

Doing

git clone https://github.com/emacs-lsp/lsp-docker    

and

docker pull emacslsp/lsp-docker-langservers

with

;; Uncomment the next line if you are using this from source
;; (add-to-list 'load-path "<path-to-lsp-docker-dir>")
(require 'lsp-docker)

(defvar lsp-docker-client-packages
    '(lsp-css lsp-clients lsp-bash lsp-go lsp-pylsp lsp-html lsp-typescript
      lsp-terraform lsp-clangd))

(setq lsp-docker-client-configs
    '((:server-id bash-ls :docker-server-id bashls-docker :server-command "bash-language-server start")
      (:server-id clangd :docker-server-id clangd-docker :server-command "clangd")
      (:server-id css-ls :docker-server-id cssls-docker :server-command "css-languageserver --stdio")
      (:server-id dockerfile-ls :docker-server-id dockerfilels-docker :server-command "docker-langserver --stdio")
      (:server-id gopls :docker-server-id gopls-docker :server-command "gopls")
      (:server-id html-ls :docker-server-id htmls-docker :server-command "html-languageserver --stdio")
      (:server-id pylsp :docker-server-id pyls-docker :server-command "pylsp")
      (:server-id ts-ls :docker-server-id tsls-docker :server-command "typescript-language-server --stdio")))

(require 'lsp-docker)
(lsp-docker-init-clients
  :path-mappings '(("my/paths" . "/projects"))
  :client-packages lsp-docker-client-packages
  :client-configs lsp-docker-client-configs)
    

does not work. lsp correctly sets up the project, but the container fails to start and crashes with error 126.

Relevant Error Messages:

Warning (initialization): An error occurred while loading ‘/Users/caseyhoward/.emacs.d/init.el’:

: No such client dockerfile-ls

Commenting out the dockerfile-ls line:

 Warning (initialization): An error occurred while loading ‘/Users/caseyhoward/.emacs.d/init.el’:

: No such client ts-ls

Commenting out that line loads the init file correctly.

However, opening a python file results in

image

Everything seems to work but the VM will not start correctly (after several restarts of both the container and the docker backend).

container name missing suffix for lsp--client-uri->path-fn

Describe the bug
After starting a language server (intelephense in my case) and executing lsp-ui-peek-find-workspace-symbol I get this error:

Tramp-Buffer:

Error: No such container: lsp-langserver

Messages:

Tramp: Opening connection for lsp-langserver using docker...
Tramp: Sending command ‘exec docker  exec -it  lsp-langserver sh’
Tramp: Waiting for prompts from remote shell...
Tramp failed to connect.  If this happens repeatedly, try
    ‘M-x tramp-cleanup-this-connection’
Tramp: Waiting for prompts from remote shell...failed
Tramp: Opening connection for lsp-langserver using docker...failed
Cleaning up the recentf list...done (0 removed)
tramp-signal-hook-function: Tramp failed to connect.  If this happens repeatedly, try
    ‘M-x tramp-cleanup-this-connection’

According to @yyoncho in Gitter:

lsp--client-uri->path-fn is set to the client wihtout the ID
at some point we should copy the client and pass the proper lsp--client-uri->path-fn

To Reproduce

  • Open a project and wait for language server to start
  • Execute lsp-ui-peek-find-workspace-symbol

Expected behavior
The function should open a tramp connection to the docker container with the proper name

Which Language Server did you use
intelephense

OS

031 ~ ➜ uname -a
Linux voidwalker 5.8.16_1 emacs-lsp/lsp-mode#1 SMP Sat Oct 17 12:21:35 UTC 2020 x86_64 GNU/Linux

`clangd` cannot be found in `$PATH`

In the README.org, lsp-docker-client-configs designates server-command as clangd. But actually, clangd executable does not exist in the $PATH of the container.

It does exist as /ccls/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clangd.

One trivial work around is changing server-command from clangd to /ccls/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clangd. Now, I can use this package with the modification.

But in principle, I think we should modify the docker image. I tried building the image with the /lsp-docker-langservers/dockerfile in this repository, but it fails. I will register another issue about this.

Failed to open multiple workspace folder

when open the second project, lsp-docker tries to start another container with the same name.
/usr/bin/docker: Error response from daemon: Conflict. The container name "/lsp-container-2" is already in use by container "47f937f70efa5a6dba94c3ea5fd36a445fbe0c2c8303f6975660a53725a5ff44". You have to remove (or rename) that container to be able to reuse that name.
See '/usr/bin/docker run --help'.

[rust-analyzer] source path not mapping for lsp-lens commands

rust-analyzer with lsp-docker works well in my environment, but for functions with lens, it reports path not found, and the path is a 'destination-path' in docker, i think it may due to the source-destination mapping not handled in this case?

"No such directory: /workspace/xxxx"

this /workspace is a path in my docker container.

Static container name stops other language servers from starting

Description
The docker container is started with a static name. This prevents more than one container running.

Solution
Change lsp-docker-launch-new-container to inject a random number into the container name:

(defun lsp-docker-launch-new-container (docker-container-name path-mappings docker-image-id server-command)
  (split-string
   (--doto (format "docker run --name %s --rm -i %s %s %s"
                   (format "%s-%d" docker-container-name (random 1000))
                   (->> path-mappings
                        (-map (-lambda ((path . docker-path))
                                (format "-v %s:%s" path docker-path)))
                        (s-join " "))
                   docker-image-id
                   server-command))
   " "))

Per-project dockerized Python virtual environment

Hello there, as mentioned in the object, I would like to create a per-project docker, such that each of them contain a project-specific Python virtual environment where installing (among others) the pylsp package.

The idea would be to have some dir-locals explicitly selecting the dockerized version of the pylsp server instead of the system-wide installed one.

I read multiple times the documentation of this repo and the one from the lsp-mode, though I cannot yet achieve my goal.

In a first attempt I tried with the following .lsp-docker.yml file:

lsp:
  server:
    type: docker
    subtype: image
    name: "mylspserver" # manually created image with this name
    server: "pylsp" 
    launch_command: "pylsp"
  mappings:
    - source: "."
      destination: "/code"

Hence invoking lsp-docker-register would install this server, but I guess this simply replaces the global lang-server for Python, as switching to another project still shows the same server connection pointing to mylspserver.

I then tried to create a unique ID client in lsp with:

(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection "pylsp")
                  :activation-fn (lsp-activate-on "python")
                  :server-id 'my-fancy-pylsp))

Changing the server key-word in .lsp-docker.yml to my-fancy-pylsp allow me to keep pylsp server intact and just add the my-fancy-pylsp. Though I don't know how to prevent other projects from pointing at my-fancy-pylsp.

This seconds approach is not nice as it implies to always create a new server (for each new project) with a unique name that is not local to the project.

Am I missing something here? Is it possible at all to achieve my goal?

If a neat solution can be found, I am willing to add this use-case to the lsp-docker documentation with a MR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.