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

Allow rustic-compile to accept a command argument #59

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 13 additions & 15 deletions rustic-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -537,21 +537,19 @@ buffer."
;;; Interactive

;;;###autoload
(defun rustic-compile (&optional arg)
"Compile rust project.

If the variable `compilation-read-command' is non-nil or if
`rustic-compile` is called with prefix argument ARG then read the
command in the minibuffer. Otherwise use
`rustic-compile-command'.

In either store the used command in `compilation-arguments'."
(interactive "P")
(rustic-set-compilation-arguments
(if (or compilation-read-command arg)
(compilation-read-command (or (car compilation-arguments)
(rustic-compile-command)))
(rustic-compile-command)))
(defun rustic-compile (command)
"Run COMMAND in the current Rust workspace root.

Interactively, prompts for the command if the variable
`compilation-read-command' is non-nil; otherwise uses
`rustic-compile-command'."
(interactive
(list
(if compilation-read-command
(compilation-read-command (or (car compilation-arguments)
(rustic-compile-command)))
(rustic-compile-command))))
(rustic-set-compilation-arguments command)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new behavior is nice!

(setq compilation-directory (funcall rustic-compile-directory-method))
(rustic-compilation-process-live)
(rustic-compilation-start (split-string (car compilation-arguments))
Expand Down
6 changes: 2 additions & 4 deletions test/rustic-clippy-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
(let* ((buffer1 (get-buffer-create "b1"))
(string "fn main() { String::from(' ').extend(String::from(' ').chars()); } ")
(formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n")
(dir (rustic-babel-generate-project t))
(compilation-read-command nil))
(dir (rustic-babel-generate-project t)))
(let* ((default-directory dir)
(src (concat dir "/src"))
(file1 (expand-file-name "main.rs" src))
Expand Down Expand Up @@ -63,8 +62,7 @@
(let* ((buffer1 (get-buffer-create "b1"))
(string "ffn main() { String::from(' ').extend(String::from(' ').chars()); } ")
(formatted-string "fn main() {\n String::from(' ').push_str(&String::from(' '));\n}\n")
(dir (rustic-babel-generate-project t))
(compilation-read-command nil))
(dir (rustic-babel-generate-project t)))
(let* ((default-directory dir)
(src (concat dir "/src"))
(file1 (expand-file-name "main.rs" src))
Expand Down
26 changes: 19 additions & 7 deletions test/rustic-compile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@

(ert-deftest rustic-test-compile ()
(let* ((dir (rustic-babel-generate-project t)))
(should-not compilation-directory)
(should-not compilation-arguments)
(setq compilation-arguments "cargo fmt")
(let* ((default-directory dir)
(proc (rustic-compile "cargo fmt")))
(should (process-live-p proc))
(while (eq (process-status proc) 'run)
(sit-for 0.1))
(should (string= compilation-directory dir))
(let ((proc (rustic-recompile)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing rustic-recompile here ? From a quick look the previous code doesn't seem to have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code does have it

(let ((proc (rustic-recompile)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new test for compiling interactively rather than via lisp, so the diff looks a little weird.

(while (eq (process-status proc) 'run)
(sit-for 0.1)))
(should (string= (car compilation-arguments) "cargo fmt"))
(should (string= compilation-directory dir))))
(setq compilation-directory nil)
(setq compilation-arguments nil))

(ert-deftest rustic-test-compile-interactive ()
(let* ((dir (rustic-babel-generate-project t)))
(let* ((default-directory dir)
(compilation-read-command nil)
(proc (rustic-compile)))
(proc (call-interactively 'rustic-compile)))
(should (process-live-p proc))
(while (eq (process-status proc) 'run)
(sit-for 0.1))
Expand All @@ -107,10 +120,9 @@
(let* ((string "fn main() { let s = 1;}")
(buf (rustic-test-count-error-helper-new string))
(default-directory (file-name-directory (buffer-file-name buf)))
(rustic-format-trigger nil)
(compilation-read-command nil))
(rustic-format-trigger nil))
(with-current-buffer buf
(let* ((proc (rustic-compile))
(let* ((proc (rustic-compile "cargo build"))
(buffer (process-buffer proc)))
(while (eq (process-status proc) 'run)
(sit-for 0.01))
Expand Down
6 changes: 2 additions & 4 deletions test/rustic-window-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
(ert-deftest rustic-test-window-count ()
(should (= (length (window-list)) 1))
(let* ((dir (rustic-babel-generate-project t)))
(setq compilation-arguments "cargo fmt")
(let* ((default-directory dir)
(compilation-read-command nil))
(rustic-compile)
(let* ((default-directory dir))
(rustic-compile "cargo fmt")
(rustic-test--wait-till-finished rustic-compilation-buffer-name)
(should (= (length (window-list)) 2))
(should (get-buffer-window rustic-compilation-buffer-name)))))
Expand Down