Minor visibility and formatting improvements.

This commit is contained in:
Nicholas Nethercote
2024-02-29 09:09:19 +11:00
parent c475e2303b
commit c1f01638af
3 changed files with 20 additions and 15 deletions

View File

@@ -130,8 +130,8 @@ impl Margin {
fn was_cut_right(&self, line_len: usize) -> bool {
let right =
if self.computed_right == self.span_right || self.computed_right == self.label_right {
// Account for the "..." padding given above. Otherwise we end up with code lines that
// do fit but end in "..." as if they were trimmed.
// Account for the "..." padding given above. Otherwise we end up with code lines
// that do fit but end in "..." as if they were trimmed.
self.computed_right - 6
} else {
self.computed_right
@@ -657,9 +657,9 @@ pub struct HumanEmitter {
}
#[derive(Debug)]
pub struct FileWithAnnotatedLines {
pub file: Lrc<SourceFile>,
pub lines: Vec<Line>,
pub(crate) struct FileWithAnnotatedLines {
pub(crate) file: Lrc<SourceFile>,
pub(crate) lines: Vec<Line>,
multiline_depth: usize,
}
@@ -724,8 +724,9 @@ impl HumanEmitter {
.skip(left)
.take_while(|ch| {
// Make sure that the trimming on the right will fall within the terminal width.
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
// For now, just accept that sometimes the code line will be longer than desired.
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char`
// is. For now, just accept that sometimes the code line will be longer than
// desired.
let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1);
if taken + next > right - left {
return false;
@@ -2228,8 +2229,8 @@ impl HumanEmitter {
buffer.puts(*row_num - 1, max_line_num_len + 3, &line, Style::NoStyle);
*row_num += 1;
}
// If the last line is exactly equal to the line we need to add, we can skip both of them.
// This allows us to avoid output like the following:
// If the last line is exactly equal to the line we need to add, we can skip both of
// them. This allows us to avoid output like the following:
// 2 - &
// 2 + if true { true } else { false }
// 3 - if true { true } else { false }
@@ -2586,6 +2587,7 @@ fn num_overlap(
let extra = if inclusive { 1 } else { 0 };
(b_start..b_end + extra).contains(&a_start) || (a_start..a_end + extra).contains(&b_start)
}
fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
num_overlap(
a1.start_col.display,