Switches to pylsp

Maybe it heavier, but at least its working. However pyvenv was a PITA.
This commit is contained in:
2022-10-28 17:50:17 +02:00
parent 76b9a837b3
commit 8547b93747

21
.emacs
View File

@@ -189,8 +189,7 @@
) )
(custom-set-faces (custom-set-faces
'(lsp-ui-doc-background ((t (:background "#373B41"))))) '(lsp-ui-doc-background ((t (:background "#373B41")))))
(add-to-list 'lsp-disabled-clients 'pyls)
(add-to-list 'lsp-enabled-clients 'jedi)
:bind ( :bind (
("C-c C-d" . lsp-ui-doc-toggle) ("C-c C-d" . lsp-ui-doc-toggle)
) )
@@ -237,6 +236,7 @@
(python-mode . (lambda () (setq-local company-prescient-sort-length-enable nil))) (python-mode . (lambda () (setq-local company-prescient-sort-length-enable nil)))
(python-mode . (lambda () (setq-local fill-column 88))) (python-mode . (lambda () (setq-local fill-column 88)))
(python-mode . lsp-deferred) (python-mode . lsp-deferred)
(python-mode . atu/activate-venv)
(lsp-managed-mode . (lambda () (lsp-managed-mode . (lambda ()
(when (derived-mode-p 'python-mode) (when (derived-mode-p 'python-mode)
(setq atu/flycheck-local-cache '((lsp . ((next-checkers . (python-flake8))))))))) (setq atu/flycheck-local-cache '((lsp . ((next-checkers . (python-flake8)))))))))
@@ -264,6 +264,7 @@
(nth 0 (split-string (buffer-string)))))) (nth 0 (split-string (buffer-string))))))
venv-name) venv-name)
) )
(defun atu/get-venv-name () (defun atu/get-venv-name ()
"Gets venv name from project root. Support .venv and .direnv structure" "Gets venv name from project root. Support .venv and .direnv structure"
(or (atu/get-dotvenv) (atu/get-direnv-venv)) (or (atu/get-dotvenv) (atu/get-direnv-venv))
@@ -272,8 +273,11 @@
(defun atu/activate-venv () (defun atu/activate-venv ()
"Activate python environment according to the project root" "Activate python environment according to the project root"
(when-let ((venv-name (atu/get-venv-name))) (when-let ((venv-name (atu/get-venv-name)))
(setenv "WORKON_HOME" venv-name)
(pyvenv-mode) (pyvenv-mode)
(pyvenv-workon venv-name) (pyvenv-workon venv-name)
(pyvenv-activate venv-name)
(message (format "Using python: %s" venv-name))
) )
) )
@@ -294,6 +298,12 @@
(flycheck-mode)) (flycheck-mode))
) )
(defun atu/pyls-set-jedi-environment ()
"Sets the jedi environment according to the discovered venv"
(when-let ((venv-name (atu/get-venv-name)))
(setq lsp-pylsp-plugins-jedi-environment venv-name))
)
(defun atu/append-workspace-extra-paths () (defun atu/append-workspace-extra-paths ()
"Appends needed extra-paths to lsp-jedi workspace if found" "Appends needed extra-paths to lsp-jedi workspace if found"
(when-let* ((venv-name (atu/get-venv-name)) (when-let* ((venv-name (atu/get-venv-name))
@@ -316,17 +326,14 @@
(flycheck-add-next-checker 'lsp 'python-pylint) (flycheck-add-next-checker 'lsp 'python-pylint)
) )
) )
:hook :hook
(python-mode . atu/activate-venv) (python-mode . atu/pyls-set-jedi-environment)
;(python-mode . atu/activate-flycheck) ;(python-mode . atu/activate-flycheck)
(python-mode . atu/append-workspace-extra-paths) ;(python-mode . atu/append-workspace-extra-paths)
(lsp-managed-mode . atu/flycheck-set-python-paths) (lsp-managed-mode . atu/flycheck-set-python-paths)
) )
(use-package lsp-jedi )
(use-package blacken (use-package blacken
:commands blacken-mode blacken-buffer :commands blacken-mode blacken-buffer