Skip to content

Commit 567a49b

Browse files
authored
lsp-rust: honour :environment for runnables (#4694)
1 parent 521108a commit 567a49b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Add ~lsp-bash-allowed-shells~ to configure supported ~sh-shell~ values.
3030
* Add hint about ~activation-fn~ for unsupported buffers.
3131
* Add Roc support
32+
* Add support for environment variables in rust analyzer runnables. Allowing the new ~Update Tests (Expect)~ code lens to work as expected.
3233

3334
** 9.0.0
3435
* Add language server config for QML (Qt Modeling Language) using qmlls.

clients/lsp-rust.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,19 +1505,25 @@ such as imports and dyn traits."
15051505
Extract the arguments, prepare the minor mode (cargo-process-mode if possible)
15061506
and run a compilation"
15071507
(-let* (((&rust-analyzer:Runnable :kind :label :args) runnable)
1508-
((&rust-analyzer:RunnableArgs :cargo-args :executable-args :workspace-root? :expect-test?) args)
1508+
((&rust-analyzer:RunnableArgs :cargo-args :executable-args :workspace-root? :expect-test? :environment?) args)
15091509
(default-directory (or workspace-root? default-directory)))
15101510
(if (not (string-equal kind "cargo"))
15111511
(lsp--error "'%s' runnable is not supported" kind)
15121512
(compilation-start
15131513
(string-join (append (when expect-test? '("env" "UPDATE_EXPECT=1"))
1514+
(when environment? (lsp-rust-analyzer--to-bash-env environment?))
15141515
(list "cargo") cargo-args
15151516
(when executable-args '("--")) executable-args '()) " ")
15161517

15171518
;; cargo-process-mode is nice, but try to work without it...
15181519
(if (functionp 'cargo-process-mode) 'cargo-process-mode nil)
15191520
(lambda (_) (concat "*" label "*"))))))
15201521

1522+
(defun lsp-rust-analyzer--to-bash-env (env-vars)
1523+
"Extract the environment variables from plist ENV-VARS."
1524+
(cl-loop for (key value) on env-vars by 'cddr
1525+
collect (format "%s=%s" (substring (symbol-name key) 1) value)))
1526+
15211527
(defun lsp-rust-analyzer-run (runnable)
15221528
"Select and run a RUNNABLE action."
15231529
(interactive (list (lsp-rust-analyzer--select-runnable)))

lsp-protocol.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ See `-let' for a description of the destructuring mechanism."
449449
(rust-analyzer:MoveItemParams (:textDocument :range :direction) nil)
450450
(rust-analyzer:RunnablesParams (:textDocument) (:position))
451451
(rust-analyzer:Runnable (:label :kind :args) (:location))
452-
(rust-analyzer:RunnableArgs (:cargoArgs :executableArgs) (:workspaceRoot :expectTest))
452+
(rust-analyzer:RunnableArgs (:cargoArgs :executableArgs) (:workspaceRoot :expectTest :environment))
453453
(rust-analyzer:RelatedTestsParams (:textDocument :position) nil)
454454
(rust-analyzer:RelatedTests (:runnable) nil)
455455
(rust-analyzer:SsrParams (:query :parseOnly) nil)

0 commit comments

Comments
 (0)