From 54975a06d41eb142077aaf2732bfe563a26efa31 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 21 Mar 2024 11:51:15 -0500 Subject: [PATCH 1/4] test: Clarify test case name --- tests/fixtures/no-color/{one_past.svg => ann_removed_nl.svg} | 0 tests/fixtures/no-color/{one_past.toml => ann_removed_nl.toml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/fixtures/no-color/{one_past.svg => ann_removed_nl.svg} (100%) rename tests/fixtures/no-color/{one_past.toml => ann_removed_nl.toml} (100%) diff --git a/tests/fixtures/no-color/one_past.svg b/tests/fixtures/no-color/ann_removed_nl.svg similarity index 100% rename from tests/fixtures/no-color/one_past.svg rename to tests/fixtures/no-color/ann_removed_nl.svg diff --git a/tests/fixtures/no-color/one_past.toml b/tests/fixtures/no-color/ann_removed_nl.toml similarity index 100% rename from tests/fixtures/no-color/one_past.toml rename to tests/fixtures/no-color/ann_removed_nl.toml From 01ca512f66fc38f9fd3ce6f4ad103e97fb91ffd2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 21 Mar 2024 11:53:17 -0500 Subject: [PATCH 2/4] test: Show existing EOF annotation behavior --- tests/fixtures/no-color/ann_eof.svg | 33 ++++++++++++++++++++++++++++ tests/fixtures/no-color/ann_eof.toml | 12 ++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/fixtures/no-color/ann_eof.svg create mode 100644 tests/fixtures/no-color/ann_eof.toml diff --git a/tests/fixtures/no-color/ann_eof.svg b/tests/fixtures/no-color/ann_eof.svg new file mode 100644 index 0000000..ba3b204 --- /dev/null +++ b/tests/fixtures/no-color/ann_eof.svg @@ -0,0 +1,33 @@ + + + + + + + error: expected `.`, `=` + + --> Cargo.toml:1:5 + + | + + 1 | asdf + + | + + | + + + + diff --git a/tests/fixtures/no-color/ann_eof.toml b/tests/fixtures/no-color/ann_eof.toml new file mode 100644 index 0000000..313d220 --- /dev/null +++ b/tests/fixtures/no-color/ann_eof.toml @@ -0,0 +1,12 @@ +[message] +level = "Error" +title = "expected `.`, `=`" + +[[message.snippets]] +source = "asdf" +line_start = 1 +origin = "Cargo.toml" +[[message.snippets.annotations]] +label = "" +level = "Error" +range = [4, 4] From 0e820651c901ed2772a842d45d033f1c6ff1c5e9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 21 Mar 2024 11:54:45 -0500 Subject: [PATCH 3/4] test: Show existing empty span behavior --- tests/fixtures/no-color/ann_insertion.svg | 33 ++++++++++++++++++++++ tests/fixtures/no-color/ann_insertion.toml | 12 ++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/fixtures/no-color/ann_insertion.svg create mode 100644 tests/fixtures/no-color/ann_insertion.toml diff --git a/tests/fixtures/no-color/ann_insertion.svg b/tests/fixtures/no-color/ann_insertion.svg new file mode 100644 index 0000000..ba3b204 --- /dev/null +++ b/tests/fixtures/no-color/ann_insertion.svg @@ -0,0 +1,33 @@ + + + + + + + error: expected `.`, `=` + + --> Cargo.toml:1:5 + + | + + 1 | asdf + + | + + | + + + + diff --git a/tests/fixtures/no-color/ann_insertion.toml b/tests/fixtures/no-color/ann_insertion.toml new file mode 100644 index 0000000..ffd2140 --- /dev/null +++ b/tests/fixtures/no-color/ann_insertion.toml @@ -0,0 +1,12 @@ +[message] +level = "Error" +title = "expected `.`, `=`" + +[[message.snippets]] +source = "asf" +line_start = 1 +origin = "Cargo.toml" +[[message.snippets.annotations]] +label = "'d' belongs here" +level = "Error" +range = [2, 2] From 7310fd4c45ed2d92f0ecabb155ba8e5a3bb86bb2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 21 Mar 2024 11:58:03 -0500 Subject: [PATCH 4/4] fix: Allow empty spans --- src/renderer/display_list.rs | 14 ++++++++------ tests/fixtures/no-color/ann_eof.svg | 2 +- tests/fixtures/no-color/ann_insertion.svg | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/renderer/display_list.rs b/src/renderer/display_list.rs index 53caa38..4d2836a 100644 --- a/src/renderer/display_list.rs +++ b/src/renderer/display_list.rs @@ -1057,6 +1057,7 @@ fn format_body( Range { start, .. } if start > line_end_index => true, Range { start, end } if start >= line_start_index && end <= line_end_index + // Allow annotating eof or stripped eol || start == line_end_index && end - start <= 1 => { if let DisplayLine::Source { @@ -1068,14 +1069,15 @@ fn format_body( .chars() .map(|c| unicode_width::UnicodeWidthChar::width(c).unwrap_or(0)) .sum::(); - // This allows for annotations to be placed one past the - // last character - let safe_end = (end - line_start_index).saturating_sub(line_length); - let annotation_end_col = line[0..(end - line_start_index) - safe_end] + let mut annotation_end_col = line + [0..(end - line_start_index).min(line_length)] .chars() .map(|c| unicode_width::UnicodeWidthChar::width(c).unwrap_or(0)) - .sum::() - + safe_end; + .sum::(); + if annotation_start_col == annotation_end_col { + // At least highlight something + annotation_end_col += 1; + } span_left_margin = min(span_left_margin, annotation_start_col); span_right_margin = max(span_right_margin, annotation_end_col); diff --git a/tests/fixtures/no-color/ann_eof.svg b/tests/fixtures/no-color/ann_eof.svg index ba3b204..c8900d0 100644 --- a/tests/fixtures/no-color/ann_eof.svg +++ b/tests/fixtures/no-color/ann_eof.svg @@ -24,7 +24,7 @@ 1 | asdf - | + | ^ | diff --git a/tests/fixtures/no-color/ann_insertion.svg b/tests/fixtures/no-color/ann_insertion.svg index ba3b204..b15b81b 100644 --- a/tests/fixtures/no-color/ann_insertion.svg +++ b/tests/fixtures/no-color/ann_insertion.svg @@ -18,13 +18,13 @@ error: expected `.`, `=` - --> Cargo.toml:1:5 + --> Cargo.toml:1:3 | - 1 | asdf + 1 | asf - | + | ^ 'd' belongs here |