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

Add ability to define docker lsp clients only for certain paths #39

Open aidalgol opened 3 years ago

aidalgol commented 3 years ago

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.

factyy commented 2 years ago

@aidalgol , take a look into the current implementation: if you use wrapper functions (like lsp-docker-register) with a valid configuration, it will register an lsp docker client only for this particular path (in case you are using single folder mapping as in your example).