Skip to content

use rust-buffer-crate to get remote crate path #449

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

Merged
merged 1 commit into from
Jun 24, 2022
Merged
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
43 changes: 25 additions & 18 deletions rust-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,31 @@

(defun rust-buffer-project ()
"Get project root if possible."
;; 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 (call-process rust-cargo-bin nil t nil "locate-project")))
(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)))))))
(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 (call-process rust-cargo-bin nil t nil "locate-project")))
(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'."
(let ((dir (locate-dominating-file default-directory "Cargo.toml")))
(if dir dir default-directory)))

(defun rust-update-buffer-project ()
(setq-local rust-buffer-project (rust-buffer-project)))
Expand Down