forked from rust-lang/annotate-snippets-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Feedback #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
Closed
Feedback #1
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
94b964f
test: Add more tests from rustc
Muscraft b09c48d
feat: Style `: ` for titles
Muscraft c4d3b6d
fix: Don't style ' ' before '|'
Muscraft 3bc1c77
fix: Style ' ' after file sigil
Muscraft c7ea1f3
fix: Add pipe to first snippet when not alone
Muscraft 8a06822
fix: Left align line numbers
Muscraft 67dde28
feat: Better match rustc's internal renderer
Muscraft 8db6a7e
feat: Right align line numbers
Muscraft 589e338
feat!: Move to new API
Muscraft 0fd1bd9
refactor: Remove dependency on rustc_hash
Muscraft 2709a60
refactor: Remove dependency on indexmap
Muscraft 348f6cc
feat: Add Suggestions
Muscraft 8baffc8
feat: Add unicode support
Muscraft 0f011fe
test: Add a test for source highlighting
Muscraft 6c5ee37
feat: Add ability to highlight source code
Muscraft a12b7dd
test: Add a test for passing precolored text
Muscraft 4266504
feat: Don't normailze title text
Muscraft 3c110d7
docs: Add when text is normalized
Muscraft 08c6692
test: Add tests margin cutting
Muscraft b61153d
fix: Handle margin cutting when encountering multibyte chars
Muscraft 22c225f
test: Add tests for custom Levels
Muscraft ae14bfb
feat: Add custom Levels
Muscraft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use annotate_snippets::{Level, Renderer, Snippet}; | ||
use annotate_snippets::{level::Level, AnnotationKind, Group, Renderer, Snippet}; | ||
|
||
#[divan::bench] | ||
fn simple() -> String { | ||
|
@@ -24,24 +24,26 @@ fn simple() -> String { | |
_ => continue, | ||
} | ||
}"#; | ||
let message = Level::Error.title("mismatched types").id("E0308").snippet( | ||
Snippet::source(source) | ||
.line_start(51) | ||
.origin("src/format.rs") | ||
.annotation( | ||
Level::Warning | ||
.span(5..19) | ||
.label("expected `Option<String>` because of return type"), | ||
) | ||
.annotation( | ||
Level::Error | ||
.span(26..724) | ||
.label("expected enum `std::option::Option`"), | ||
), | ||
let message = Level::ERROR.message("mismatched types").id("E0308").group( | ||
Group::new().element( | ||
Snippet::source(source) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain the new API in the commit or PR? For example, why was a |
||
.line_start(51) | ||
.origin("src/format.rs") | ||
.annotation( | ||
AnnotationKind::Context | ||
.span(5..19) | ||
.label("expected `Option<String>` because of return type"), | ||
) | ||
.annotation( | ||
AnnotationKind::Primary | ||
.span(26..724) | ||
.label("expected enum `std::option::Option`"), | ||
), | ||
), | ||
); | ||
|
||
let renderer = Renderer::plain(); | ||
let rendered = renderer.render(message).to_string(); | ||
let rendered = renderer.render(message); | ||
rendered | ||
} | ||
|
||
|
@@ -67,19 +69,21 @@ fn fold(bencher: divan::Bencher<'_, '_>, context: usize) { | |
(input, span) | ||
}) | ||
.bench_values(|(input, span)| { | ||
let message = Level::Error.title("mismatched types").id("E0308").snippet( | ||
Snippet::source(&input) | ||
.fold(true) | ||
.origin("src/format.rs") | ||
.annotation( | ||
Level::Warning | ||
.span(span) | ||
.label("expected `Option<String>` because of return type"), | ||
), | ||
let message = Level::ERROR.message("mismatched types").id("E0308").group( | ||
Group::new().element( | ||
Snippet::source(&input) | ||
.fold(true) | ||
.origin("src/format.rs") | ||
.annotation( | ||
AnnotationKind::Context | ||
.span(span) | ||
.label("expected `Option<String>` because of return type"), | ||
), | ||
), | ||
); | ||
|
||
let renderer = Renderer::plain(); | ||
let rendered = renderer.render(message).to_string(); | ||
let rendered = renderer.render(message); | ||
rendered | ||
}); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use annotate_snippets::renderer::OutputTheme; | ||
use annotate_snippets::{level::Level, AnnotationKind, Group, Renderer, Snippet}; | ||
|
||
fn main() { | ||
let source = r#"//@ compile-flags: -Ztreat-err-as-bug | ||
//@ failure-status: 101 | ||
//@ error-pattern: aborting due to `-Z treat-err-as-bug=1` | ||
//@ error-pattern: [eval_static_initializer] evaluating initializer of static `C` | ||
//@ normalize-stderr: "note: .*\n\n" -> "" | ||
//@ normalize-stderr: "thread 'rustc' panicked.*:\n.*\n" -> "" | ||
//@ rustc-env:RUST_BACKTRACE=0 | ||
|
||
#![crate_type = "rlib"] | ||
|
||
pub static C: u32 = 0 - 1; | ||
//~^ ERROR could not evaluate static initializer | ||
"#; | ||
let message = Level::ERROR | ||
.text(Some("error: internal compiler error")) | ||
.message("could not evaluate static initializer") | ||
.id("E0080") | ||
.group( | ||
Group::new().element( | ||
Snippet::source(source) | ||
.origin("$DIR/err.rs") | ||
.fold(true) | ||
.annotation( | ||
AnnotationKind::Primary | ||
.span(386..391) | ||
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"), | ||
), | ||
), | ||
); | ||
|
||
let renderer = Renderer::styled().theme(OutputTheme::Unicode); | ||
anstream::println!("{}", renderer.render(message)); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use annotate_snippets::renderer::OutputTheme; | ||
use annotate_snippets::{level::Level, AnnotationKind, Group, Patch, Renderer, Snippet}; | ||
|
||
fn main() { | ||
let source = r#"// Regression test for issue #114529 | ||
// Tests that we do not ICE during const eval for a | ||
// break-with-value in contexts where it is illegal | ||
|
||
#[allow(while_true)] | ||
fn main() { | ||
[(); { | ||
while true { | ||
break 9; //~ ERROR `break` with value from a `while` loop | ||
}; | ||
51 | ||
}]; | ||
|
||
[(); { | ||
while let Some(v) = Some(9) { | ||
break v; //~ ERROR `break` with value from a `while` loop | ||
}; | ||
51 | ||
}]; | ||
|
||
while true { | ||
break (|| { //~ ERROR `break` with value from a `while` loop | ||
let local = 9; | ||
}); | ||
} | ||
} | ||
"#; | ||
let message = Level::ERROR | ||
.message("`break` with value from a `while` loop") | ||
.id("E0571") | ||
.group( | ||
Group::new().element( | ||
Snippet::source(source) | ||
.line_start(1) | ||
.origin("$DIR/issue-114529-illegal-break-with-value.rs") | ||
.fold(true) | ||
.annotation( | ||
AnnotationKind::Primary | ||
.span(483..581) | ||
.label("can only break with a value inside `loop` or breakable block"), | ||
) | ||
.annotation( | ||
AnnotationKind::Context | ||
.span(462..472) | ||
.label("you can't `break` with a value in a `while` loop"), | ||
), | ||
), | ||
) | ||
.group( | ||
Group::new() | ||
.element( | ||
Level::HELP | ||
.text(Some("suggestion")) | ||
.title("use `break` on its own without a value inside this `while` loop"), | ||
) | ||
.element( | ||
Snippet::source(source) | ||
.line_start(1) | ||
.origin("$DIR/issue-114529-illegal-break-with-value.rs") | ||
.fold(true) | ||
.patch(Patch::new(483..581, "break")), | ||
), | ||
); | ||
|
||
let renderer = Renderer::styled().theme(OutputTheme::Unicode); | ||
anstream::println!("{}", renderer.render(message)); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
its not a refactor if its user visible.
This is also a breaking change and should be called out