diff --git a/lsp-bridge.el b/lsp-bridge.el index 68742180ff..bfbafe05ec 100644 --- a/lsp-bridge.el +++ b/lsp-bridge.el @@ -1241,6 +1241,24 @@ 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))) + + ;; When `lsp-bridge-python-command' is the default value (ie: python[3.X]), + ;; use the original value of the environment variable `PATH', + ;; otherwise add the `pyvenv' bin directory to the head of the `PATH' environment variable. + (cl-pushnew (concat "PATH=" (cond ((not pyvenv-bin-path) path) + ((not (file-exists-p pyvenv-bin-path)) path) + ((string-match-p pyvenv-bin-path path) path) + (t (prog2 + (message "[LSP-Bridge] Add '%s' to executable path." pyvenv-bin-path) + (string-join (list pyvenv-bin-path path) path-separator))))) environments) + environments)) + (defun lsp-bridge-start-process () "Start LSP-Bridge process if it isn't started." (if (lsp-bridge-process-live-p) @@ -1265,7 +1283,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