Fix label ordering for ranges that are the same

Labels that cover the same range are now rendered in the order that they were specified in the diagnostic (as opposed to in reverse order). This means that this diagnostic:

```
   ┌─ same_range:1:7
   │
 1 │ ::S { }
   │     - Expected '('
   │     ^ Unexpected '{'
   │
```

…will now be rendered as:

```
   ┌─ same_range:1:7
   │
 1 │ ::S { }
   │     ^ Unexpected '{'
   │     - Expected '('
   │
```

Closes #231
This commit is contained in:
Brendan Zabarauskas
2020-04-21 10:40:22 +10:00
parent e0d5a8a959
commit 528ed97d2e
3 changed files with 6 additions and 3 deletions
+4 -1
View File
@@ -143,7 +143,10 @@ where
// to piggyback off its lexicographic comparison implementation.
(range.start, range.end).cmp(&(label_start, label_end))
}) {
Ok(index) | Err(index) => index,
// If the ranges are the same, order the labels as they
// originally were specified in the diagnostic.
Ok(index) => index + 1,
Err(index) => index,
};
line.single_labels
@@ -7,8 +7,8 @@ expression: TEST_DATA.emit_color(&config)
{fg:Blue}┌─{/} same_range:1:5
{fg:Blue}│{/}
{fg:Blue}1{/} {fg:Blue}│{/} ::S { }
{fg:Blue}│{/} {fg:Blue}- Expected '('{/}
{fg:Blue}│{/} {fg:Red}^ Unexpected '{'{/}
{fg:Blue}│{/} {fg:Blue}- Expected '('{/}
{fg:Blue}│{/}
@@ -7,8 +7,8 @@ error: Unexpected token
┌─ same_range:1:5
1 │ ::S { }
│ - Expected '('
│ ^ Unexpected '{'
│ - Expected '('