emacs-lsp / lsp-docker

Scripts and configurations to leverage lsp-mode in docker environment
GNU General Public License v3.0
243 stars 34 forks source link

Use with other language-servers #24

Closed minikN closed 3 years ago

minikN commented 3 years ago

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.

yyoncho commented 3 years ago
(require 'lsp-docker)

(defvar lsp-docker-client-packages '(lsp-php))

(defvar lsp-docker-client-configs
  (list
   (list :server-id '<server-id> :docker-server-id '<server-id>-docker :server-command "<command to start the language server with>")))

(require 'lsp-docker)
(lsp-docker-init-clients
 :docker-image-id "<your image-id>"
 :path-mappings '(("<path-to-projects-you-want-to-use>" . "/projects"))
 :client-packages lsp-docker-client-packages
 :client-configs lsp-docker-client-configs)

something like that should do. Populate the <>.

minikN commented 3 years ago

@yyoncho Thank you.

I actually had trouble understanding how to use my own container even after your example. However. I finally figured it out looking at the source:

(cl-defun lsp-docker-init-clients (&key
                    path-mappings
                    (docker-image-id "emacslsp/lsp-docker-langservers")
                    (docker-container-name "lsp-container")
                    (priority 10)
                    (client-packages lsp-docker-default-client-packages)
                    (client-configs lsp-docker-default-client-configs))
  "Loads the required client packages and registers the required clients to run with docker."
  (seq-do (lambda (package) (require package nil t)) client-packages)
  (seq-do (-lambda ((&plist :server-id :docker-server-id :server-command))
        (lsp-docker-register-client
         :server-id server-id
         :priority priority
         :docker-server-id docker-server-id
         :docker-image-id docker-image-id
         :docker-container-name docker-container-name
         :server-command server-command
         :path-mappings path-mappings
         :launch-server-cmd-fn #'lsp-docker-launch-new-container))
      client-configs))

You seem to hardcode the container name. Is it possible to change this? In my opinion it would be nice to be able to define one container for each language and start them individually when opening a file for such language.

yyoncho commented 3 years ago

You seem to hardcode the container name.

No. This is the elisp syntax for providing a default value.

minikN commented 3 years ago

You seem to hardcode the container name.

No. This is the elisp syntax for providing a default value.

Sorry for the confusion. I adapted my config like such:

;; Docker
(defvar lsp-docker-client-packages
    '(lsp-php))

(defvar lsp-docker-client-configs
   (list
   (list :server-id 'php-ls :docker-server-id 'phpls-docker :server-command "intelephense --stdio")))

(require 'lsp-docker)
(lsp-docker-init-clients
  :docker-image-id "lsp-docker-php"
  :docker-container-name "lsp-docker-php"
  :path-mappings '(("/path/to/project" . "/projects"))
  :client-packages lsp-docker-client-packages
  :client-configs lsp-docker-client-configs)

where /path/to/project is actually a valid path.

I created a Dockerfile:

FROM php:7.4-fpm-alpine

RUN apk add --update npm
RUN npm i intelephense -g

I also named the image lsp-docker-php.

When opening a php file from the project it starts the container but then messages:

LSP :: Error from the Language Server: Request initialize failed with mesage: Cannot read proprty 'dataPaths' of null (Internal Error)

I wasn't able to find anything releated on Intelephense's issue tracker. I don't know if this is related to lsp-docker or not.

Thanks in advance.

yyoncho commented 3 years ago

The proper :server-id is iph

minikN commented 3 years ago

Thank you, it works now.