diff --git a/.emacs b/.emacs index 1d3fed4..fe1ca57 100644 --- a/.emacs +++ b/.emacs @@ -189,8 +189,7 @@ ) (custom-set-faces '(lsp-ui-doc-background ((t (:background "#373B41"))))) - (add-to-list 'lsp-disabled-clients 'pyls) - (add-to-list 'lsp-enabled-clients 'jedi) + :bind ( ("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 fill-column 88))) (python-mode . lsp-deferred) + (python-mode . atu/activate-venv) (lsp-managed-mode . (lambda () (when (derived-mode-p 'python-mode) (setq atu/flycheck-local-cache '((lsp . ((next-checkers . (python-flake8))))))))) @@ -264,6 +264,7 @@ (nth 0 (split-string (buffer-string)))))) venv-name) ) + (defun atu/get-venv-name () "Gets venv name from project root. Support .venv and .direnv structure" (or (atu/get-dotvenv) (atu/get-direnv-venv)) @@ -272,8 +273,11 @@ (defun atu/activate-venv () "Activate python environment according to the project root" (when-let ((venv-name (atu/get-venv-name))) + (setenv "WORKON_HOME" venv-name) (pyvenv-mode) (pyvenv-workon venv-name) + (pyvenv-activate venv-name) + (message (format "Using python: %s" venv-name)) ) ) @@ -294,6 +298,12 @@ (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 () "Appends needed extra-paths to lsp-jedi workspace if found" (when-let* ((venv-name (atu/get-venv-name)) @@ -316,17 +326,14 @@ (flycheck-add-next-checker 'lsp 'python-pylint) ) ) - :hook - (python-mode . atu/activate-venv) + (python-mode . atu/pyls-set-jedi-environment) ;(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) ) -(use-package lsp-jedi ) - (use-package blacken :commands blacken-mode blacken-buffer