annotate-snippets-rs
annotate-snippets-rs copied to clipboard
fix: Tweak rendering of `source` when it's a single ASCII whitespace
This PR includes a small fix (that I am not at all sure about) and a regression test that fails on current master.
The input here is just a single ASCII whitespace with an annotation pointing to immediately after that whitespace. In current master, it gets rendered like this:
error: missing trailing newline at end of file
|
1 | ...
| ^ W292
|
= help: Add trailing newline
But I think the insertion of an ellipsis here is not quite right. I was certainly confused by the output.
I don't really understand the formatting code at all, but I believe the ellipsis is being inserted by this code:
if self.margin.was_cut_left() {
// We have stripped some code/whitespace from the beginning, make it clear.
buffer.puts(line_offset, code_offset, "...", *lineno_color);
}
And self.margin.was_cut_left() was returning true because
computed_left was set to 18446744073709551593. This kind of value
seems like a bug, although some margin values are explicitly
initialized to usize::MAX, so maybe not.
Anywho, I tried removing the condition gating the setting of
whitespace_margin, and that seems to fix this specific case without
any other known regressions (including across all of ruff's test
suite), but this was mostly a result of me feeling around in the dark
here.