diff options
| author | brotzeit <brotzeitmacher@gmail.com> | 2022-06-24 13:55:20 +0200 |
|---|---|---|
| committer | brotzeit <brotzeitmacher@gmail.com> | 2022-06-24 14:05:53 +0200 |
| commit | 3e73d670220dd4045bfde60a03faa201777db204 (patch) | |
| tree | f1e18c01a437c6babe28b6e429912e14a5d4fb47 | |
| parent | af4aa18a9ba7ef9e7dbc1bcae0f4f58fc21f5a4f (diff) | |
| download | rust-mode-3e73d670220dd4045bfde60a03faa201777db204.tar.gz | |
use rust-buffer-crate to get remote crate path
| -rw-r--r-- | rust-cargo.el | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/rust-cargo.el b/rust-cargo.el index 9f6e611..090945a 100644 --- a/rust-cargo.el +++ b/rust-cargo.el @@ -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))) |
