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

Org babel: Ability to include compilation failure, panic as part of result block #25

Merged
merged 3 commits into from
Aug 2, 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
4 changes: 3 additions & 1 deletion CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
- ~rustic-recompile~ will remember any universal arguments that is
passed to it.
- Fix ~rustic-cargo-upgrade~ in the presence of universal arguments.
- Fix ~rusti-cargo-clippy-rerun~ to use the last used arguments.
- Fix ~rustic-cargo-clippy-rerun~ to use the last used arguments.
- Implement ~rustic-babel-display-error-popup~ customization
option. Refer the variable docs for more details.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ Customization:
of babel process
- `rustic-babel-auto-wrap-main` wrap body into main function
- `rustic-babel-default-toolchain` active toolchain for babel blocks
- `rustic-babel-display-error-popup` displays error popup on
compilation failure or when the exit code is non zero. Set it to nil
if you want it to be displayed as part of result block.

### lsp-mode

Expand Down
19 changes: 15 additions & 4 deletions rustic-babel.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
:type 'boolean
:group 'rustic-babel)

(defcustom rustic-babel-display-error-popup t
"Diplay compilation error or panic in error popup.
On failures and panic during execution, should the error be
displayed separately or as part of popup or should it be part of
results block ? By default we display it as separate popup."
:type 'boolean
:group 'rustic-babel)

(defcustom rustic-babel-auto-wrap-main t
"Whether to auto wrap body in `fn main' to function call if none exists."
:type 'boolean
Expand Down Expand Up @@ -158,12 +166,15 @@ execution with rustfmt."
(save-excursion
(save-match-data
(goto-char (point-min))
(when (re-search-forward "^thread '[^']+' panicked at .*")
(goto-char (match-beginning 0))
(setq result (buffer-substring-no-properties (point) (line-end-position)))))))
(if rustic-babel-display-error-popup
(when (re-search-forward "^thread '[^']+' panicked at .*")
(goto-char (match-beginning 0))
(setq result (buffer-substring-no-properties (point) (line-end-position))))
(setq result (buffer-string))))))
(rustic-babel-run-update-result-block result)
(rustic-with-spinner rustic-babel-spinner nil nil)
(pop-to-buffer proc-buffer)))))
(when rustic-babel-display-error-popup
(pop-to-buffer proc-buffer))))))

(defun rustic-babel-build-update-result-block (result)
"Update result block with RESULT."
Expand Down
10 changes: 10 additions & 0 deletions test/rustic-babel-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
(should (eq (rustic-test-babel-check-results buf) nil))
(should-not (buffer-live-p rustic-babel-compilation-buffer-name))))

(ert-deftest rustic-test-babel-error-no-popup ()
(let* ((string "fn main() {
panic!(\"hello world\");
}")
(buf (rustic-test-get-babel-block string))
(rustic-babel-display-error-popup nil))
(rustic-test-babel-execute-block buf)
;; The output will have some message of panic
(should (s-contains? "panic" (rustic-test-babel-check-results buf)))))

(ert-deftest rustic-test-babel-error-results ()
(let* ((string "fn main() {
let v = vec![1, 2, 3];
Expand Down
Loading