-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lsp-bridge 找不到虚拟环境中安装的 lsp-server 命令 #1103 #1104
Conversation
直接模仿 EAF 项目中, 环境变量通过 Elisp 这边构建会不会更简单? https://github.com/emacs-eaf/emacs-application-framework/blob/4310ecdc8b6ba23107f7cfae59d509decbd06d90/eaf.el#L652 ? |
我按照 eaf 中那种方式重新写了过后的确比较简单,不用修改 lsp-bridge.py 文件。 |
fef4615
to
d062df4
Compare
本地运行测试通不过,我不知道怎么排查了 |
CI 显示你byte compile lsp-bridge.el 的时候有报错, 报错修复应该就好了 |
lsp-bridge.el
Outdated
(defun lsp-bridge--build-process-environment () | ||
"Create lsp-bridge subprocess process environments" | ||
(let* ((path (getenv "PATH")) | ||
(pyvenv-prefix (string-trim (shell-command-to-string | ||
(format "%s -c \"%s\"" lsp-bridge-python-command "import sys;print(sys.prefix)")))) | ||
(pyvenv-bin-path (expand-file-name "bin" pyvenv-prefix)) | ||
(environments (seq-filter (lambda (env) (not (string-match-p "^PATH=" env))) | ||
process-environment))) | ||
;; Add python venv path | ||
(add-to-list 'environments | ||
(concat "PATH=" (if (string-match-p pyvenv-bin-path path) | ||
path | ||
(string-join (list pyvenv-bin-path path) path-separator))) | ||
t) | ||
environments)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(defun lsp-bridge--build-process-environment ()
"Create lsp-bridge subprocess process environments"
(let* ((path (getenv "PATH"))
(python-path (executable-find lsp-bridge-python-command))
(pyvenv-bin-path (expand-file-name "bin"
(directory-file-name
(file-name-directory python-path))))
(new-path (if (string-match-p pyvenv-bin-path path)
path
(concat pyvenv-bin-path path-separator path))))
(cons (concat "PATH=" new-path)
(seq-remove (lambda (env)
(string-prefix-p "PATH=" env))
process-environment))))
AI 给了一个版本哈, 你测试一下。
我的意思是, 你获取 sys.prefix 不要用 shell-command-to-string 的方法, 这样会导致 lsp-bridge 启动的时候会有一个额外的进程启动开销, 影响启动速度
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果直接拼接路径,对于那种使用软连接的有问题。比如: 把 python 路径连接到 .local/bin 中, 设置这个 lsp-bridge-python-command 就会失败,我也觉得这种使用方法用问题。 那我就更改成拼接路径的形式,限制这种非正常情况的使用。
ef2bb25
to
b7ef41a
Compare
大佬, 这个对于没有虚拟环境的有没有影响? 还有, 大佬添加一下注释吧, 要不是以后别的开发者看不懂 |
没有,默认值或找不到 bin 路径就使用默认的环境变量值 |
大佬, elisp byte compile 编译不过的话, CI就过不了 |
大佬,已经解决了,本地test通过了 |
感谢大佬的补丁。 |
大佬 Sorry,这个补丁有问题。可以回退吗? 它会影响那些启用了虚拟环境的项目的补全情况。因为它使用的是为 lsp-bridge 创建的环境,补全结果就有问题。实际启动 basedpyright 应该是使用的是项目的环境,补全才能成功。 @manateelazycat |
Done f6b63f7 |
问题详解:
单独为 lsp-bridge 创建一个
python
虚拟环境时(lsp-bridge
所有与python
相关依赖都将安装这个环境中,如:basedpyright
)。配置了lsp-bridge-python-command
值后,启动lsp-bridge
时出现找不到语言服务器的命令的错误。我觉得如果配置了
lsp-bridge-python-command
,那么其环境中安装的东西应该是 lsp-bridge 优先使用的,其次才查询系统环境的实现或者失败。解决思路:
python
虚拟环境未激活情况下,直接使用虚拟环境的python
命令运行脚本时,其继承的是系统环境的PATH
。所以当执行subprocess
和shutil.which
等代码时,其PATH
未包含虚拟环境bin
目录. 所以解决问题方法是将虚拟环境的bin
目录直接添加PATH
最前面。