Skip to content

Commit

Permalink
fix lsp-server in pyvenv environment not found
Browse files Browse the repository at this point in the history
  • Loading branch information
awerdx520 authored and tangxin1 committed Nov 12, 2024
1 parent c4520d6 commit b7ef41a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,23 @@ So we build this macro to restore postion after code format."
(interactive)
(lsp-bridge-call-async "profile_dump"))

(defun lsp-bridge--build-process-environment ()
"Create lsp-bridge subprocess process environments"
(let ((path (getenv "PATH"))
(pyvenv-bin-path (file-name-directory lsp-bridge-python-command))
(environments (seq-filter (lambda (env) (not (string-match-p "^PATH=" env)))
process-environment)))
;; Add python venv path
(add-to-list 'environments
(concat "PATH="
(if (not pyvenv-bin-path)
path
(if (string-match-p pyvenv-bin-path path)
path
(string-join (list pyvenv-bin-path path) path-separator))))
t)
environments))

(defun lsp-bridge-start-process ()
"Start LSP-Bridge process if it isn't started."
(if (lsp-bridge-process-live-p)
Expand All @@ -1249,7 +1266,8 @@ So we build this macro to restore postion after code format."
(setq lsp-bridge-internal-process-args lsp-bridge-args))

;; Start python process.
(let ((process-connection-type (not (lsp-bridge--called-from-wsl-on-windows-p))))
(let ((process-connection-type (not (lsp-bridge--called-from-wsl-on-windows-p)))
(process-environment (lsp-bridge--build-process-environment)))
(setq lsp-bridge-internal-process
(apply 'start-process
lsp-bridge-name lsp-bridge-name
Expand Down

0 comments on commit b7ef41a

Please sign in to comment.