Skip to content

Commit

Permalink
Correctly handle directory on rerun
Browse files Browse the repository at this point in the history
Currently rustic will override the default-directory to the workspace root after
a compilation is finished. This enables it to correctly find the paths in error
messages. But it also means that if you rerun a command it will rerun in the
root crate instead of the original one.

This change adds a new variable to track the original directory and resets it
when we rerun.
  • Loading branch information
CeleritasCelery committed Apr 9, 2024
1 parent 39423d1 commit 64cf248
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rustic-cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ When calling this function from `rustic-popup-mode', always use the value of
(defun rustic-cargo-test-rerun ()
"Run 'cargo test' with `rustic-test-arguments'."
(interactive)
(rustic-cargo-test-run rustic-test-arguments))
(let ((default-directory (or rustic-compilation-directory default-directory)))
(rustic-cargo-test-run rustic-test-arguments)))

;;;###autoload
(defun rustic-cargo-current-test ()
Expand Down Expand Up @@ -617,7 +618,8 @@ When calling this function from `rustic-popup-mode', always use the value of
(defun rustic-cargo-run-rerun ()
"Run 'cargo run' with `rustic-run-arguments'."
(interactive)
(rustic-cargo-run-command rustic-run-arguments))
(let ((default-directory (or rustic-compilation-directory default-directory)))
(rustic-cargo-run-command rustic-run-arguments)))

(defun rustic--get-run-arguments ()
"Helper utility for getting arguments related to 'examples' directory."
Expand Down
4 changes: 4 additions & 0 deletions rustic-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ Error matching regexes from compile.el are removed."

;;; Compilation Process

(defvar-local rustic-compilation-directory nil
"original directory for rust compilation process.")

(defvar rustic-compilation-process-name "rustic-compilation-process"
"Process name for rust compilation processes.")

Expand Down Expand Up @@ -251,6 +254,7 @@ Set environment variables for rust process."
(erase-buffer)
(setq default-directory dir)
(funcall mode)
(setq-local rustic-compilation-directory dir)
(unless no-mode-line
(setq mode-line-process
'((:propertize ":%s" face compilation-mode-line-run)
Expand Down

0 comments on commit 64cf248

Please sign in to comment.