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

Adds a customization to default to workspace or local crate. #546

Merged
merged 2 commits into from
May 20, 2024
Merged
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion rust-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
:type 'boolean
:group 'rust-mode)

(defcustom rust-locate-project-in-workspace t
"Whether to use `--workspace` with `cargo locate-project`. If t,
rust-mode will run commands for the entire workspace. If nil,
rust will search for the Cargo.toml in the local crated"
:type 'boolean
:group 'rust-mode)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we change this to rust-cargo-locate-default-arguments ? It's default value could be (list "--workspace"). For your specific use case, you can pass it as nil.

This will give you the ability to pass any arbitrary arguments to locate-project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(defcustom rust-cargo-default-arguments ""
"Default arguments when running common cargo commands."
:type 'string
Expand All @@ -42,7 +49,11 @@
(setq-local process-environment env)
;; Set PATH so we can find cargo.
(setq-local exec-path path)
(let ((ret (process-file rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project" "--workspace")))
(let ((ret
(let ((args (list rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project")))
(when rust-locate-project-in-workspace
(setq args (append args (list "--workspace"))))
(apply #'process-file args))))
(when (/= ret 0)
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
(goto-char 0)
Expand Down
Loading