Skip to content

Commit

Permalink
Merge pull request #1104 from awerdx520/dev
Browse files Browse the repository at this point in the history
lsp-bridge 找不到虚拟环境中安装的 lsp-server 命令 #1103
  • Loading branch information
manateelazycat authored Nov 13, 2024
2 parents d9647c1 + c09f417 commit d46260f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit d46260f

Please sign in to comment.