-
Notifications
You must be signed in to change notification settings - Fork 199
Python virtualenv
zy9306 edited this page Aug 1, 2022
·
3 revisions
Since not every virtualenv has installed epc, you may need to configure lsp-bridge-python-command
as the environment to run epc.
First, ensure that virtualenv
and virtualenvwrapper
are installed and the WORKON_HOME
exists.(That is, the workon
command works properly.)
Install pyvenv: https://github.com/jorgenschaefer/pyvenv
Then add following to you config.(Please change the path to your own.)
(defun local/lsp-bridge-get-single-lang-server-by-project (project-path filepath)
(let* ((json-object-type 'plist)
(custom-dir (expand-file-name ".cache/lsp-bridge/pyright" user-emacs-directory))
(custom-config (expand-file-name "pyright.json" custom-dir))
(default-config (json-read-file (expand-file-name "repo/lsp-bridge/langserver/pyright.json" user-emacs-directory)))
(settings (plist-get default-config :settings))
)
(plist-put settings :pythonPath (executable-find "python"))
(make-directory (file-name-directory custom-config) t)
(with-temp-file custom-config
(insert (json-encode default-config)))
custom-config))
(add-hook 'python-mode-hook (lambda () (setq-local lsp-bridge-get-single-lang-server-by-project 'local/lsp-bridge-get-single-lang-server-by-project)))
(add-hook 'pyvenv-post-activate-hooks
(lambda ()
(lsp-bridge-restart-process)))
You can also use the name associated with the project name as the custom json file.
Always restart lsp-bridge when you switch venv.