Skip to content
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

Fix #130 prevent cargo metadata warnings from breaking everything #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions cargo-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,28 @@ If FILE-NAME is not a TRAMP file, return it unmodified."
(nth 6 (tramp-dissect-file-name file-name))
file-name))

(defun cargo-process--call-process-to-string (command &rest ARGS)
"Executes `command` and returns its output(std out) as string."
(let* ((err-file (make-temp-file "cargo-error"))
(output (with-output-to-string
(with-current-buffer
standard-output
(apply #'call-process command nil (list t err-file) nil ARGS))))
(std-err (with-output-to-string
(with-current-buffer
standard-output
(insert-file-contents err-file)))))
(when (length std-err)
(message "cargo-stderr: %s" std-err))
(delete-file err-file)
output))

(defun cargo-process--workspace-root ()
"Find the workspace root using `cargo metadata`."
(when (cargo-process--project-root)
(let* ((metadata-text (shell-command-to-string
(concat (shell-quote-argument cargo-process--custom-path-to-bin)
" metadata --format-version 1 --no-deps")))
(let* ((metadata-text (cargo-process--call-process-to-string
cargo-process--custom-path-to-bin
"metadata" "--format-version" "1" "--no-deps"))
(metadata-json (cargo-json-read-from-string metadata-text))
(tramp-prefix (cargo-process--tramp-file-name-prefix (cargo-process--project-root)))
(workspace-root (concat tramp-prefix
Expand Down Expand Up @@ -406,8 +422,8 @@ Returns the created process."
(with-current-buffer (get-buffer-create "*rust errno*")
(let ((buffer-read-only nil))
(erase-buffer)
(insert (shell-command-to-string
(concat cargo-process--rustc-cmd " --explain=" errno))))
(insert (cargo-process--call-process-to-string
cargo-process--rustc-cmd "--explain" errno)))
(markdown-view-mode)
(setq-local markdown-fontify-code-blocks-natively t)
(setq-local markdown-fontify-code-block-default-mode 'rust-mode)
Expand Down