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 references to source code in compilation buffer for rustc 1.24 #56

Merged
merged 1 commit into from
May 21, 2018
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
15 changes: 13 additions & 2 deletions cargo-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,37 @@ Always set to nil if cargo-process--enable-rust-backtrace is nil"
(setenv cargo-process--rust-backtrace "1")
(setenv cargo-process--rust-backtrace nil))))

(defun cargo-process--workspace-root ()
"Find the worksapce root using `cargo metadata`."
(let* ((metadata-text (shell-command-to-string
(concat cargo-process--custom-path-to-bin " metadata --format-version 1 --no-deps")))
(metadata-json (json-read-from-string metadata-text))
(workspace-root (alist-get 'workspace_root metadata-json)))
workspace-root))


(defun cargo-process--start (name command &optional last-command)
"Start the Cargo process NAME with the cargo command COMMAND."
(set-rust-backtrace command)
(let* ((buffer (concat "*Cargo " name "*"))
(project-root (cargo-process--project-root))
(cmd
(or last-command
(cargo-process--maybe-read-command
(mapconcat #'identity (list cargo-process--custom-path-to-bin
command
"--manifest-path" (concat project-root "Cargo.toml")
cargo-process--command-flags)
" "))))
(project-root (cargo-process--project-root))
(default-directory (or project-root default-directory)))
(save-some-buffers (not compilation-ask-about-save)
(lambda ()
(and project-root
buffer-file-name
(string-prefix-p project-root (file-truename buffer-file-name)))))
(setq cargo-process-last-command (list name command cmd))
(compilation-start cmd 'cargo-process-mode (lambda(_) buffer))
(let ((default-directory (cargo-process--workspace-root)))
(compilation-start cmd 'cargo-process-mode (lambda(_) buffer)))
(set-process-sentinel (get-buffer-process buffer) 'cargo-process--finished-sentinel)))

(defun cargo-process--explain-action (button)
Expand Down