Skip to content
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-rust: honour :environment for runnables #4694

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Add ~lsp-bash-allowed-shells~ to configure supported ~sh-shell~ values.
* Add hint about ~activation-fn~ for unsupported buffers.
* Add Roc support
* Add support for environment variables in rust analyzer runnables. Allowing the new ~Update Tests (Expect)~ code lens to work as expected.

** 9.0.0
* Add language server config for QML (Qt Modeling Language) using qmlls.
Expand Down
8 changes: 7 additions & 1 deletion clients/lsp-rust.el
Original file line number Diff line number Diff line change
Expand Up @@ -1505,19 +1505,25 @@ such as imports and dyn traits."
Extract the arguments, prepare the minor mode (cargo-process-mode if possible)
and run a compilation"
(-let* (((&rust-analyzer:Runnable :kind :label :args) runnable)
((&rust-analyzer:RunnableArgs :cargo-args :executable-args :workspace-root? :expect-test?) args)
((&rust-analyzer:RunnableArgs :cargo-args :executable-args :workspace-root? :expect-test? :environment?) args)
(default-directory (or workspace-root? default-directory)))
(if (not (string-equal kind "cargo"))
(lsp--error "'%s' runnable is not supported" kind)
(compilation-start
(string-join (append (when expect-test? '("env" "UPDATE_EXPECT=1"))
(when environment? (lsp-rust-analyzer--to-bash-env environment?))
(list "cargo") cargo-args
(when executable-args '("--")) executable-args '()) " ")

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

(defun lsp-rust-analyzer--to-bash-env (env-vars)
"Extract the environment variables from plist ENV-VARS."
(cl-loop for (key value) on env-vars by 'cddr
collect (format "%s=%s" (substring (symbol-name key) 1) value)))

(defun lsp-rust-analyzer-run (runnable)
"Select and run a RUNNABLE action."
(interactive (list (lsp-rust-analyzer--select-runnable)))
Expand Down
2 changes: 1 addition & 1 deletion lsp-protocol.el
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ See `-let' for a description of the destructuring mechanism."
(rust-analyzer:MoveItemParams (:textDocument :range :direction) nil)
(rust-analyzer:RunnablesParams (:textDocument) (:position))
(rust-analyzer:Runnable (:label :kind :args) (:location))
(rust-analyzer:RunnableArgs (:cargoArgs :executableArgs) (:workspaceRoot :expectTest))
(rust-analyzer:RunnableArgs (:cargoArgs :executableArgs) (:workspaceRoot :expectTest :environment))
(rust-analyzer:RelatedTestsParams (:textDocument :position) nil)
(rust-analyzer:RelatedTests (:runnable) nil)
(rust-analyzer:SsrParams (:query :parseOnly) nil)
Expand Down
Loading