icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Highlight Arrow is 1 Column Off #652

Closed InsertCreativityHere closed 1 year ago

InsertCreativityHere commented 1 year ago

This arrow should be pointing to column 13, but if you actually count the columns, it's pointing to column 14.

error [E002]: invalid syntax: unknown symbol ';'
 --> test.slice:2:13
  |
2 | module Hello;
  |             /\
  |

This PR fixes this by subtracting one from the number of whitespace characters we emit when using an arrow highlight.

The problem occurred because the logic was built for underlines like '_', where the underline starts at the same column as the highlight. With the arrow though, the '/' should actually appear in the column before the highlight.

InsertCreativityHere commented 1 year ago

Maybe we could drop this altogether and only use the _ highlights. If the locations are the same, just do (location, location+1) instead of having a special /\ or character.

There's only 3 places this can happen, and 2 are always at the end of a line anyways: 1) We hit EOF while in the middle of a grammar rule

error [E002]: invalid syntax: expected one of 'identifier', but found 'EOF'
 --> test.slice:2:7
  |
2 | module
  |      /\
  |

2) We hit a newline in the middle of an inline tag:

warning [MalformedDocComment]: missing a closing '}' on an inline doc comment tag
 --> test.slice:4:24
  |
4 | /// Hello there {@link
  |                      /\
  |

3) Whenever the parser fails with a UnrecognizedToken error. I'm not sure exactly what kinds of syntax errors would trigger it.