Skip to content

Commit 56e5c3a

Browse files
authored
Merge pull request #449 from rust-lang/remote-crate-path
use rust-buffer-crate to get remote crate path
2 parents af4aa18 + 3e73d67 commit 56e5c3a

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

rust-cargo.el

+25-18
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,31 @@
3030

3131
(defun rust-buffer-project ()
3232
"Get project root if possible."
33-
;; Copy environment variables into the new buffer, since
34-
;; with-temp-buffer will re-use the variables' defaults, even if
35-
;; they have been changed in this variable using e.g. envrc-mode.
36-
;; See https://github.com/purcell/envrc/issues/12.
37-
(let ((env process-environment)
38-
(path exec-path))
39-
(with-temp-buffer
40-
;; Copy the entire environment just in case there's something we
41-
;; don't know we need.
42-
(setq-local process-environment env)
43-
;; Set PATH so we can find cargo.
44-
(setq-local exec-path path)
45-
(let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
46-
(when (/= ret 0)
47-
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
48-
(goto-char 0)
49-
(let ((output (json-read)))
50-
(cdr (assoc-string "root" output)))))))
33+
(if (file-remote-p default-directory)
34+
(rust-buffer-crate)
35+
;; Copy environment variables into the new buffer, since
36+
;; with-temp-buffer will re-use the variables' defaults, even if
37+
;; they have been changed in this variable using e.g. envrc-mode.
38+
;; See https://github.com/purcell/envrc/issues/12.
39+
(let ((env process-environment)
40+
(path exec-path))
41+
(with-temp-buffer
42+
;; Copy the entire environment just in case there's something we
43+
;; don't know we need.
44+
(setq-local process-environment env)
45+
;; Set PATH so we can find cargo.
46+
(setq-local exec-path path)
47+
(let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
48+
(when (/= ret 0)
49+
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
50+
(goto-char 0)
51+
(let ((output (json-read)))
52+
(cdr (assoc-string "root" output))))))))
53+
54+
(defun rust-buffer-crate ()
55+
"Try to locate Cargo.toml using `locate-dominating-file'."
56+
(let ((dir (locate-dominating-file default-directory "Cargo.toml")))
57+
(if dir dir default-directory)))
5158

5259
(defun rust-update-buffer-project ()
5360
(setq-local rust-buffer-project (rust-buffer-project)))

0 commit comments

Comments
 (0)