-
Notifications
You must be signed in to change notification settings - Fork 1
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
Print context of violations #45
Conversation
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.
Amazing, this looks so much better.
I think I've figured out a fix to the weird off-by-one error, but I haven't tested it enough to be 100% sure.
src/lib.rs
Outdated
let snippet = Level::Warning.title(&message_line).snippet( | ||
Snippet::source(&content_slice) | ||
.line_start(start_index) | ||
.annotation(Level::Error.span(label_offset..label_offset).label(code)), |
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.
.annotation(Level::Error.span(label_offset..label_offset).label(code)), | |
.annotation(Level::Error.span(label_offset..label_offset.saturating_add(1)).label(code)), |
src/lib.rs
Outdated
// put the annotation in the first column: it's either in column 2 | ||
// or the end of the previous line. But does appear to be right | ||
// for other columns! | ||
let label_offset = offset_up_to_line + col.saturating_sub(1).max(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.
let label_offset = offset_up_to_line + col.saturating_sub(1).max(1); | |
let label_offset = offset_up_to_line + col.saturating_sub(1); |
As an aside, it might be nice to introduce a |
Example:
A couple of annoying things:
put the annotation in the first column: it's either in column 2
or the end of the previous line. But does appear to be right
for other columns!
message. Might be fixed in future version of annotate-snippets
-- or we use an earlier version with more control.
.origin(path)
to get the filename andline:col automatically, but see above about off-by-one error