Skip to content

Commit f1a4210

Browse files
committed
For lsp-custom-settings values, supports function and extracts lambda out
1 parent 9cabe53 commit f1a4210

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

lsp-mode.el

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6491,10 +6491,10 @@ changing the value of `foo'."
64916491
(defun lsp-register-custom-settings (props)
64926492
"Register PROPS.
64936493
PROPS is list of triple (path value boolean?) where PATH is the path to the
6494-
property; VALUE can be a literal value, symbol to be evaluated, or lambda
6495-
function to be called; BOOLEAN? is an optional flag that should be non-nil for
6496-
boolean settings, when it is nil the property will be ignored if the VALUE is
6497-
nil."
6494+
property; VALUE can be a literal value, symbol to be evaluated, or either a
6495+
function or lambda function to be called without arguments; BOOLEAN? is an
6496+
optional flag that should be non-nil for boolean settings, when it is nil the
6497+
property will be ignored if the VALUE is nil."
64986498
(let ((-compare-fn #'lsp--compare-setting-path))
64996499
(setq lsp-client-settings (-uniq (append props lsp-client-settings)))))
65006500

@@ -6520,7 +6520,9 @@ TBL - a hash table, PATHS is the path to the nested VALUE."
65206520
(mapc (-lambda ((path variable boolean?))
65216521
(when (s-matches? (concat section "\\..*") path)
65226522
(let* ((symbol-value (if (symbolp variable)
6523-
(symbol-value variable)
6523+
(if (fboundp variable)
6524+
(funcall variable)
6525+
(symbol-value variable))
65246526
(if (functionp variable)
65256527
(funcall variable) variable)))
65266528
(value (if (and boolean? (not symbol-value))

lsp-pyls.el

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@
5757
:group 'lsp-pyls
5858
:package-version '(lsp-mode . "6.1"))
5959

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-
6660
(defcustom lsp-pyls-plugins-jedi-completion-enabled t
6761
"Enable or disable the plugin."
6862
:type 'boolean
@@ -373,6 +367,26 @@ should be the python executable. This option will be prioritized over
373367
:group 'lsp-pyls
374368
:package-version '(lsp-mode . "6.3"))
375369

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+
376390
(lsp-register-custom-settings
377391
'(("pyls.rope.ropeFolder" lsp-pyls-rope-rope-folder)
378392
("pyls.rope.extensionModules" lsp-pyls-rope-extension-modules)
@@ -420,23 +434,7 @@ should be the python executable. This option will be prioritized over
420434
("pyls.plugins.jedi_completion.include_params" lsp-pyls-plugins-jedi-completion-include-params t)
421435
("pyls.plugins.jedi_completion.enabled" lsp-pyls-plugins-jedi-completion-enabled t)
422436
("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)))
440438

441439
(lsp-register-client
442440
(make-lsp-client :new-connection (lsp-stdio-connection

0 commit comments

Comments
 (0)