Skip to content

Configure snippets renderer to match rustc/Cargo style #15689

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
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ impl Shell {
writeln!(
self.err(),
"{}",
Renderer::styled().term_width(term_width).render(message)
Renderer::styled()
.note(NOTE)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a pr to annotate snippets if there is a discrepancy

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 don't understand.

shell.render_message(Level::Note.title("foo")) uses a wrong color. The snippets don't specify a color themselves by design, the color is imposed on the snippets by the stylesheet initialized by styled().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. I thought the CI test failure was a false positive:

     Summary semver requires new major version: 1 major and 0 minor checks failed
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/constructible_struct_adds_field.ron

but there's also a UI test failing.

Copy link
Contributor

Choose a reason for hiding this comment

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

The expectation is that annotate-snippets defaults are rustc's defaults. If annotate-snippets is not matching rustc, then that is a bug with annotate-snippers that should be resolved. We should not work around that bug in Cargo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, i would recommend being pretty sure about a resolution when marking things resolved, otherwise leave it to the original person. While this is a smaller PR and so its less likely to be lost, in larger PRs that can easily make it so misunderstood feedback gets lost.

.help(HELP)
.term_width(term_width)
.render(message)
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub const PLACEHOLDER: Style = AnsiColor::Cyan.on_default();
pub const ERROR: Style = AnsiColor::Red.on_default().effects(Effects::BOLD);
pub const WARN: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
pub const NOTE: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
pub const HELP: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
pub const GOOD: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
pub const VALID: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
pub const INVALID: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
4 changes: 2 additions & 2 deletions tests/testsuite/lints/error/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions tests/testsuite/lints/inherited/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testsuite/lints/warning/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading