Skip to content

Commit 3bdc304

Browse files
authored
Merge pull request #408 from brotzeit/compile-workspace
don't require Cargo.toml for compile commands
2 parents 10fbcb0 + 0da1159 commit 3bdc304

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

rustic-cargo.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ in your project like `pwd'"
619619
(let ((c (if (listp command)
620620
command
621621
(split-string command))))
622-
(rustic-compilation-start c args)))
622+
(rustic-compilation-start c (append (list :no-default-dir t) args))))
623623

624624
;;;###autoload
625625
(defun rustic-cargo-build ()

rustic-compile.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ ARGS is a plist that affects how the process is run.
288288
(process (or (plist-get args :process) rustic-compilation-process-name))
289289
(mode (or (plist-get args :mode) 'rustic-compilation-mode))
290290
(directory (or (plist-get args :directory) (funcall rustic-compile-directory-method)))
291-
(workspace (rustic-buffer-workspace))
291+
(workspace (rustic-buffer-workspace (plist-get args :no-default-dir)))
292292
(sentinel (or (plist-get args :sentinel) #'rustic-compilation-sentinel))
293293
(file-buffer (current-buffer)))
294294
(rustic-compilation-setup-buffer buf directory mode)

rustic.el

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,20 @@
6464

6565
(defun rustic-buffer-workspace (&optional nodefault)
6666
"Get workspace for the current buffer."
67+
;; this variable is buffer local so we can use the cached value
6768
(if rustic--buffer-workspace
6869
rustic--buffer-workspace
6970
(with-temp-buffer
7071
(let ((ret (call-process (rustic-cargo-bin) nil (list (current-buffer) nil) nil "locate-project" "--workspace")))
71-
(when (and (/= ret 0) (not nodefault))
72-
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
73-
(goto-char 0)
74-
(let* ((output (json-read))
75-
(dir (file-name-directory (cdr (assoc-string "root" output)))))
76-
(setq rustic--buffer-workspace dir))))))
72+
(cond ((and (/= ret 0) nodefault)
73+
(error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
74+
((and (/= ret 0) (not nodefault))
75+
(setq rustic--buffer-workspace default-directory))
76+
(t
77+
(goto-char 0)
78+
(let* ((output (json-read))
79+
(dir (file-name-directory (cdr (assoc-string "root" output)))))
80+
(setq rustic--buffer-workspace dir))))))))
7781

7882
(defun rustic-buffer-crate (&optional nodefault)
7983
"Return the crate for the current buffer.

0 commit comments

Comments
 (0)