Last active
December 13, 2023 23:45
-
-
Save yosisa/8c8fb79dd7b8c14745dbf0bbf3334a97 to your computer and use it in GitHub Desktop.
Enable lsp-docker per project basis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker/image:name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.8-buster | |
RUN pip install python-language-server[all] | |
RUN printf '#!/bin/bash \ | |
\npip install . \ | |
\npyls \ | |
\n' >/start.sh && chmod +x /start.sh | |
WORKDIR /work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package f) | |
(use-package s) | |
(use-package dash) | |
(use-package lsp-mode) | |
(use-package lsp-docker | |
:after lsp-mode | |
:straight (:host github :repo "emacs-lsp/lsp-docker") | |
:config | |
(defun my/guess-lsp-docker-project () | |
(if-let ((buffer-file buffer-file-name) | |
(dir (f--traverse-upwards (f-exists? (f-expand ".lsp-docker" it)) (f-dirname buffer-file))) | |
(file (f-join dir ".lsp-docker")) | |
(image (with-temp-buffer | |
(insert-file-contents file) | |
(s-chomp | |
(buffer-substring-no-properties (point-min) (point-max))))) | |
(n (length image))) | |
`(:root ,dir :image ,image))) | |
(cl-defun my/register-python-client (&key root image) | |
(lsp-docker-register-client | |
:server-id 'pyls | |
:priority 2 | |
:docker-server-id 'pyls-docker | |
:docker-image-id image | |
:docker-container-name (format "pyls-%s" (substring (secure-hash 'md5 root) 0 7)) | |
:server-command "/start.sh" | |
:path-mappings `((,root . "/work")) | |
:launch-server-cmd-fn #'lsp-docker-launch-new-container)) | |
(defun my/enable-lsp-docker () | |
(require 'lsp-clients) | |
(if-let ((project (my/guess-lsp-docker-project))) | |
(pcase major-mode | |
('python-mode (apply #'my/register-python-client project))))) | |
(with-eval-after-load 'python | |
(add-hook 'python-mode-hook #'my/enable-lsp-docker))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment