Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "3"
repository = "https://github.com/rust-lang/annotate-snippets-rs"
license = "MIT OR Apache-2.0"
edition = "2024"
rust-version = "1.85.0" # MSRV
rust-version = "1.88.0" # MSRV
include = [
"build.rs",
"src/**/*",
Expand Down
80 changes: 41 additions & 39 deletions src/renderer/render.rs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

chore: Bump MSRV to 1.88.0, use let chains

As noted at #378 (comment), as we don't have an MSRV policy MSRV bumps should not be done without discussion.

Also, this commit seems unrelated to this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, this commit seems unrelated to this PR

i wasn't satisfied with what the code looked like when i wrote the first commit and figured it would be a good idea to see how it renders if let chains were used. i tried and was much happier with my changes. i still kept it as a separate commit so it's easier review (and remove if y'all are ok with the code as it is at f4a9639). the other edits in c3c0622 are required to make CI pass.

Original file line number Diff line number Diff line change
Expand Up @@ -1098,27 +1098,26 @@ fn render_source_line(
if annotations_position
.iter()
.all(|(_, ann)| matches!(ann.annotation_type, LineAnnotationType::MultilineStart(_)))
&& let Some(max_pos) = annotations_position.iter().map(|(pos, _)| *pos).max()
{
if let Some(max_pos) = annotations_position.iter().map(|(pos, _)| *pos).max() {
// Special case the following, so that we minimize overlapping multiline spans.
//
// 3 │ X0 Y0 Z0
// │ ┏━━━━━┛ │ │ < We are writing these lines
// │ ┃┌───────┘ │ < by reverting the "depth" of
// │ ┃│┌─────────┘ < their multiline spans.
// 4 │ ┃││ X1 Y1 Z1
// 5 │ ┃││ X2 Y2 Z2
// │ ┃│└────╿──│──┘ `Z` label
// │ ┃└─────│──┤
// │ ┗━━━━━━┥ `Y` is a good letter too
// ╰╴ `X` is a good letter
for (pos, _) in &mut annotations_position {
*pos = max_pos - *pos;
}
// We know then that we don't need an additional line for the span label, saving us
// one line of vertical space.
line_len = line_len.saturating_sub(1);
// Special case the following, so that we minimize overlapping multiline spans.
//
// 3 │ X0 Y0 Z0
// │ ┏━━━━━┛ │ │ < We are writing these lines
// │ ┃┌───────┘ │ < by reverting the "depth" of
// │ ┃│┌─────────┘ < their multiline spans.
// 4 │ ┃││ X1 Y1 Z1
// 5 │ ┃││ X2 Y2 Z2
// │ ┃│└────╿──│──┘ `Z` label
// │ ┃└─────│──┤
// │ ┗━━━━━━┥ `Y` is a good letter too
// ╰╴ `X` is a good letter
for (pos, _) in &mut annotations_position {
*pos = max_pos - *pos;
}
// We know then that we don't need an additional line for the span label, saving us
// one line of vertical space.
line_len = line_len.saturating_sub(1);
}

// Write the column separator.
Expand Down Expand Up @@ -1447,7 +1446,29 @@ fn emit_suggestion_default(
let (complete, parts, highlights) = spliced_lines;
let is_multiline = complete.lines().count() > 1;

if matches_previous_suggestion {
if suggestion.path.as_ref() != primary_path
&& let Some(path) = suggestion.path.as_ref()
&& !matches_previous_suggestion
{
let (loc, _) = sm.span_to_locations(parts[0].span.clone());
let origin = Origin::path(path.as_ref())
.line(loc.line)
.char_column(loc.char + 1);

render_origin(
renderer,
buffer,
max_line_num_len,
&origin,
true,
is_first,
!is_cont,
row_num - 1,
);
row_num += 1;

draw_col_separator_no_space(renderer, buffer, row_num - 1, max_line_num_len + 1);
} else if matches_previous_suggestion {
buffer.puts(
row_num - 1,
max_line_num_len + 1,
Expand All @@ -1457,25 +1478,6 @@ fn emit_suggestion_default(
} else {
draw_col_separator_start(renderer, buffer, row_num - 1, max_line_num_len + 1);
}
if suggestion.path.as_ref() != primary_path {
if let Some(path) = suggestion.path.as_ref() {
if !matches_previous_suggestion {
let (loc, _) = sm.span_to_locations(parts[0].span.clone());
// --> file.rs:line:col
// |
let arrow = renderer.decor_style.file_start(is_first, false);
buffer.puts(row_num - 1, 0, arrow, ElementStyle::LineNumber);
let message = format!("{}:{}:{}", path, loc.line, loc.char + 1);
let col = usize::max(max_line_num_len + 1, arrow.len());
buffer.puts(row_num - 1, col, &message, ElementStyle::LineAndColumn);
for _ in 0..max_line_num_len {
buffer.prepend(row_num - 1, " ", ElementStyle::NoStyle);
}
draw_col_separator_no_space(renderer, buffer, row_num, max_line_num_len + 1);
row_num += 1;
}
}
}

if let DisplaySuggestion::Diff = show_code_change {
row_num += 1;
Expand Down
11 changes: 5 additions & 6 deletions src/renderer/styled_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ impl StyledBuffer {
style: ElementStyle,
overwrite: bool,
) {
if let Some(ref mut line) = self.lines.get_mut(line) {
if let Some(StyledChar { style: s, .. }) = line.get_mut(col) {
if overwrite || matches!(s, ElementStyle::NoStyle | ElementStyle::Quotation) {
*s = style;
}
}
if let Some(ref mut line) = self.lines.get_mut(line)
&& let Some(StyledChar { style: s, .. }) = line.get_mut(col)
&& (overwrite || matches!(s, ElementStyle::NoStyle | ElementStyle::Quotation))
{
*s = style;
}
}
}
Loading