-
Notifications
You must be signed in to change notification settings - Fork 183
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
Match panics in compilation-mode
#510
Conversation
rust-compile.el
Outdated
@@ -34,6 +34,12 @@ See `compilation-error-regexp-alist' for help on their format.") | |||
"Specifications for matching code references in rustc invocations. | |||
See `compilation-error-regexp-alist' for help on their format.") | |||
|
|||
(defvar rustc-panics-compilation-regexps | |||
(let ((re "thread '[^']+' panicked at \\(\\(.*\\):\\([0-9]+\\):\\([0-9]+\\)\\)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use the rustc-compilation-location
variable already in scope.
Something like this
(let ((re (concat "thread '[^']+' panicked at " rustc-compilation-location)))
(cons re '(2 3 4 nil 1)))
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip! I'll give it a go later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, you were right!
dc18006
to
e072eab
Compare
If we encounter a panic when executing Rust code in `compilation-mode`, we now correctly highlight the location where the panic occurred. For example: ``` thread 'main' panicked at src/main.rs:2:5: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` Here, `src/main.rs:2:5` is highlighted. The developer is then able to execute `compile-goto-error` to jump to the correct spot in the code. Co-authored-by: Brent Westbrook <[email protected]> Co-authored-by: zlef <[email protected]>
e072eab
to
3948fae
Compare
@@ -3618,11 +3619,13 @@ let b = 1;" | |||
("file6.rs" "132" "34" compilation-error "file6.rs:132:34")) | |||
(("file5.rs" "12" "34" compilation-info "file5.rs:12:34")) | |||
((like-previous-one "82" back-to-indentation compilation-info "82") | |||
(like-previous-one "132" back-to-indentation compilation-info "132"))) | |||
(like-previous-one "132" back-to-indentation compilation-info "132")) | |||
(("src/file7.rs" "12" "34" nil "src/file7.rs:12:34"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test now, but I'm not sure why this is nil
and not compilation-error
. Maybe someone more comfortable with Elisp can assist me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very familiar with elisp either, so I could be wrong.
Here's what I think is happening here:
compilation-error is set
(defvar compilation-error "error"
"Stem of message to print when no matches are found.")
And so an expression like ("file6.rs" "132" "34" compilation-error "file6.rs:132:34")
is equivalent to ("file6.rs" "132" "34" error "file6.rs:132:34")'
That translates to type
expression from the compilation-error-regexp-alist
help doc. I'm getting that from this paragraph:
Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
HIGHLIGHT...]). If REGEXP matches, the FILE’th subexpression
gives the file name, and the LINE’th subexpression gives the line
number. The COLUMN’th subexpression gives the column number on
that line.
The definition of our regex is
defvar rustc-panics-compilation-regexps
(let ((re (concat "thread '[^']+' panicked at " rustc-compilation-location)))
(cons re '(2 3 4 nil 1)))
"Specifications for matching panics in rustc invocations.
See `compilation-error-regexp-alist' for help on their format.")
And so we're capturing the:
2nd capture group for the file name
3rd capture group for the line number,
4th capture group for the column number,
nil for the type
1st capture group for the hyperlink.
We don't have an error
or warning
in our error message, like the others do, to parse out for the type
, so our type
is nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I think nil
is correct. That, or invent a new type like panic
. I'm not really sure.
@luckysori This looks ready for review to me. Do you mind running |
@rustbot review |
I guess it's not enabled on this repo, @zachlefevre. |
@psibi Do you mind reviewing this? |
Thanks @zachlefevre for the review and @luckysori for the PR and the test case! I have confirmed that it works for me, merging this. |
Fixes #507.
If we encounter a panic when executing Rust code in
compilation-mode
, we now correctly highlight the location where the panic occurred.For example:
Here,
src/main.rs:2:5
is highlighted. The developer is then able to executecompile-goto-error
to jump to the correct spot in the code.