|
57 | 57 | :group 'lsp-pyls |
58 | 58 | :package-version '(lsp-mode . "6.1")) |
59 | 59 |
|
60 | | -(defcustom lsp-pyls-pyenv-command-path "pyenv" |
61 | | - "Executable path to pyenv" |
62 | | - :type 'string |
63 | | - :group 'lsp-pyls |
64 | | - :package-version '(lsp-mode . "6.3")) |
65 | | - |
66 | 60 | (defcustom lsp-pyls-plugins-jedi-completion-enabled t |
67 | 61 | "Enable or disable the plugin." |
68 | 62 | :type 'boolean |
@@ -373,6 +367,26 @@ should be the python executable. This option will be prioritized over |
373 | 367 | :group 'lsp-pyls |
374 | 368 | :package-version '(lsp-mode . "6.3")) |
375 | 369 |
|
| 370 | +(defun lsp-pyls-get-pyenv-environment () |
| 371 | + "Get the pyenv-managed environment for current workspace, where |
| 372 | +<ENV>/bin/python is the corresponding Python executable" |
| 373 | + (if lsp-pyls-plugins-jedi-environment |
| 374 | + lsp-pyls-plugins-jedi-environment |
| 375 | + (when lsp-pyls-plugins-jedi-use-pyenv-environment |
| 376 | + (let ((pyenv-version (getenv "PYENV_VERSION")) |
| 377 | + (root (lsp-seq-first (lsp-find-roots-for-workspace lsp--cur-workspace (lsp-session))))) |
| 378 | + (when root |
| 379 | + (setenv "PYENV_VERSION" nil) |
| 380 | + (let* ((pyenv-command-path (executable-find "pyenv")) |
| 381 | + (python-env (f-parent |
| 382 | + (f-parent |
| 383 | + (shell-command-to-string |
| 384 | + (format "PYENV_DIR='%s' %s which python" |
| 385 | + root pyenv-command-path)))))) |
| 386 | + (lsp--info "Configure pyls with environment: %s" python-env) |
| 387 | + (setenv "PYENV_VERSION" pyenv-version) |
| 388 | + python-env)))))) |
| 389 | + |
376 | 390 | (lsp-register-custom-settings |
377 | 391 | '(("pyls.rope.ropeFolder" lsp-pyls-rope-rope-folder) |
378 | 392 | ("pyls.rope.extensionModules" lsp-pyls-rope-extension-modules) |
@@ -420,23 +434,7 @@ should be the python executable. This option will be prioritized over |
420 | 434 | ("pyls.plugins.jedi_completion.include_params" lsp-pyls-plugins-jedi-completion-include-params t) |
421 | 435 | ("pyls.plugins.jedi_completion.enabled" lsp-pyls-plugins-jedi-completion-enabled t) |
422 | 436 | ("pyls.configurationSources" lsp-pyls-configuration-sources) |
423 | | - ("pyls.plugins.jedi.environment" |
424 | | - (lambda () |
425 | | - (if lsp-pyls-plugins-jedi-environment |
426 | | - lsp-pyls-plugins-jedi-environment |
427 | | - (when lsp-pyls-plugins-jedi-use-pyenv-environment |
428 | | - (let ((pyenv-version (getenv "PYENV_VERSION")) |
429 | | - (root (lsp-seq-first (lsp-find-roots-for-workspace lsp--cur-workspace (lsp-session))))) |
430 | | - (when root |
431 | | - (setenv "PYENV_VERSION" nil) |
432 | | - (let ((python-env (f-parent |
433 | | - (f-parent |
434 | | - (shell-command-to-string |
435 | | - (format "PYENV_DIR='%s' %s which python" |
436 | | - root lsp-pyls-pyenv-command-path)))))) |
437 | | - (lsp--info "Configure pyls with environment: %s" python-env) |
438 | | - (setenv "PYENV_VERSION" pyenv-version) |
439 | | - python-env))))))))) |
| 437 | + ("pyls.plugins.jedi.environment" lsp-pyls-get-pyenv-environment))) |
440 | 438 |
|
441 | 439 | (lsp-register-client |
442 | 440 | (make-lsp-client :new-connection (lsp-stdio-connection |
|
0 commit comments