From faf6d98b3e2a386f3f37079f9bb6de11a7bce6cc Mon Sep 17 00:00:00 2001 From: yanchith Date: Thu, 25 Aug 2022 14:23:08 +0200 Subject: Make compilation buffer workspace-aware This fixes incorrect paths for workspace projects when running starting compilation from a source file instead of the project root. --- rust-cargo.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-cargo.el b/rust-cargo.el index 0c35ddb..75f9c16 100644 --- a/rust-cargo.el +++ b/rust-cargo.el @@ -44,7 +44,7 @@ (setq-local process-environment env) ;; Set PATH so we can find cargo. (setq-local exec-path path) - (let ((ret (call-process rust-cargo-bin nil t nil "locate-project"))) + (let ((ret (process-file rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project" "--workspace"))) (when (/= ret 0) (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) (goto-char 0) -- cgit v1.2.3 From 49709dceb64897f7ecff4d53abfceb2f60eb83d4 Mon Sep 17 00:00:00 2001 From: yanchith Date: Thu, 25 Aug 2022 14:35:58 +0200 Subject: Fulfil requirements of cargo locate-project --workspace --- test-project/Cargo.toml | 11 ++++++++++- test-project/src/lib.rs | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test-project/src/lib.rs diff --git a/test-project/Cargo.toml b/test-project/Cargo.toml index f741b14..7e9bea9 100644 --- a/test-project/Cargo.toml +++ b/test-project/Cargo.toml @@ -1 +1,10 @@ -# Dummy file needed for test +# Dummy file needed for test. +# +# Needs to have at least a few fields set up, because +# +# cargo locate-project --workspace +# +# will attempt to parse it and fail, if the file is empty. +[package] +name = "test-project" +version = "0.1.0" diff --git a/test-project/src/lib.rs b/test-project/src/lib.rs new file mode 100644 index 0000000..cdc8599 --- /dev/null +++ b/test-project/src/lib.rs @@ -0,0 +1,4 @@ +pub fn test_project() { + // This is only present, because cargo locate-project --workspace actually + // validates the rust project and fails if there is no target. +} -- cgit v1.2.3 From c91d4ddad81ced33bfaf54581f7fc2dc95e32b40 Mon Sep 17 00:00:00 2001 From: brotzeit Date: Thu, 25 Aug 2022 15:03:54 +0200 Subject: rust-buffer-project: don't use rust-buffer-crate when file-remote-p --- rust-cargo.el | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/rust-cargo.el b/rust-cargo.el index 75f9c16..cfbcd81 100644 --- a/rust-cargo.el +++ b/rust-cargo.el @@ -30,26 +30,24 @@ (defun rust-buffer-project () "Get project root if possible." - (if (file-remote-p default-directory) - (rust-buffer-crate) - ;; Copy environment variables into the new buffer, since - ;; with-temp-buffer will re-use the variables' defaults, even if - ;; they have been changed in this variable using e.g. envrc-mode. - ;; See https://github.com/purcell/envrc/issues/12. - (let ((env process-environment) - (path exec-path)) - (with-temp-buffer - ;; Copy the entire environment just in case there's something we - ;; don't know we need. - (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"))) - (when (/= ret 0) - (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) - (goto-char 0) - (let ((output (json-read))) - (cdr (assoc-string "root" output)))))))) + ;; Copy environment variables into the new buffer, since + ;; with-temp-buffer will re-use the variables' defaults, even if + ;; they have been changed in this variable using e.g. envrc-mode. + ;; See https://github.com/purcell/envrc/issues/12. + (let ((env process-environment) + (path exec-path)) + (with-temp-buffer + ;; Copy the entire environment just in case there's something we + ;; don't know we need. + (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"))) + (when (/= ret 0) + (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) + (goto-char 0) + (let ((output (json-read))) + (cdr (assoc-string "root" output))))))) (defun rust-buffer-crate () "Try to locate Cargo.toml using `locate-dominating-file'." -- cgit v1.2.3