Skip to content

Commit 26dd5ac

Browse files
committed
Adds a customization to default to workspace or local crate.
Adds rust-locate-project-in-workspace custom variable, which controls whether or not to locate the workspace project using `--workspace` (the default) or not. In cases where there is only one create, this should make no difference. The default setting should match the existing behavior. Github issue #545
1 parent e54bbae commit 26dd5ac

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

rust-cargo.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
:type 'boolean
2020
:group 'rust-mode)
2121

22+
(defcustom rust-locate-project-in-workspace t
23+
"Whether to use `--workspace` with `cargo locate-project`. If t,
24+
rust-mode will run commands for the entire workspace. If nil,
25+
rust will search for the Cargo.toml in the local crated"
26+
:type 'boolean
27+
:group 'rust-mode)
28+
2229
(defcustom rust-cargo-default-arguments ""
2330
"Default arguments when running common cargo commands."
2431
:type 'string
@@ -42,7 +49,11 @@
4249
(setq-local process-environment env)
4350
;; Set PATH so we can find cargo.
4451
(setq-local exec-path path)
45-
(let ((ret (process-file rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project" "--workspace")))
52+
(let ((ret
53+
(let ((args (list rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project")))
54+
(when rust-locate-project-in-workspace
55+
(setq args (append args (list "--workspace"))))
56+
(apply #'process-file args))))
4657
(when (/= ret 0)
4758
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
4859
(goto-char 0)

0 commit comments

Comments
 (0)