Skip to content

Commit

Permalink
Use cargo-metadata command to learn about workspace root
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Feb 13, 2018
1 parent ba652e4 commit b74750b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cargo-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,19 @@
(buffer-substring-no-properties (line-beginning-position)
(line-end-position))))

(defun cargo-process--workspace-root ()
"Find the worksapce root using `cargo metadata`."
(let* ((metadata-text (shell-command-to-string
"cargo 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--project-root ()
"Find the root of the current Cargo project."
(let ((root (locate-dominating-file (or buffer-file-name default-directory) "Cargo.toml")))
(let* ((guess-root (locate-dominating-file (or buffer-file-name default-directory) "Cargo.toml"))
(workspace-root (cargo-process--workspace-root))
(root (or workspace-root guess-root)))
(and root (file-truename root))))

(define-derived-mode cargo-process-mode compilation-mode "Cargo-Process."
Expand Down

0 comments on commit b74750b

Please sign in to comment.