codespan icon indicating copy to clipboard operation
codespan copied to clipboard

Wrong outer padding

Open abs0luty opened this issue 1 year ago • 0 comments

Bug description

Example of the bug:

error[E001]: expected `]` or `,`, found integer literal
  ┌─ test.ry:9:5
  │
7 │   fun main() {
8 │       let a = [1, 2
  │ ╭─────────────────'
9 │ │     3]
  │ │     ^ found integer literal
  │ ╰' expected `]` or `,`
10 │   }
  ^^ mismatched outer paddings

It's happening when i try to emit diagnostics with Config::after_label_lines set to 1.

Why does it happen? The bug appears to happen here and here.

Maybe you should take config.after_label_lines into account when calculating outer padding?

-            outer_padding = std::cmp::max(outer_padding, count_digits(end_line_number));
+            outer_padding = std::cmp::max(outer_padding, count_digits(end_line_number + self.config.after_label_lines));
-                    outer_padding = std::cmp::max(outer_padding, count_digits(line_number));
+                    outer_padding = std::cmp::max(outer_padding, count_digits(line_number) + self.config.end_context_lines);

And also, i don't quite get why do we need to use start_line_number here:

            outer_padding = std::cmp::max(outer_padding, count_digits(start_line_number));

I don't know much about the source code, but I hope that someone will make a pull request and fix this for both single and multi line labels.

[!NOTE]
Correct me, if i misinterpreted something!

abs0luty avatar Aug 15 '23 22:08 abs0luty