Diagnostic formatter doesn't account for grapheme length in its column annotations
Description
Given this code:
for (i = 🐮; i != 👩👩👦👦; i += 1) { x x }
The diagnostic formatter produces this:
1 │ for (i = 🐮; i != 👩👩👦👦; i += 1) { x x }
∣ │ │ ╰─ error: consecutive statements on a line must be separated by ';'
∣ │ ╰─ error: expected ')' to end tuple pattern
∣ ╰─ error: C-style for statement has been removed in Swift 3
2 │
Note that the consecutive statements on a line error is shown at the wrong column, because we're counting columns in terms of UTF-8 bytes rather than in terms of grapheme cluster. We'll need to update the column calculation to operate in terms of "column width per grapheme cluster" so we get the right locations for the annotations.
Steps to Reproduce
Paste that code into a file for.swift, and run swift-parser-cli print-diags for.swift.
rdar://106093487
https://github.com/apple/swift-syntax/pull/1365
Ah whoops, that's where Doug noticed the issue, not where it's fixed :)
I’ve got the same problem with my backtracing code, as you might imagine, and I’d already added code to deal with the common cases. What we really need is the East Asian Width tables (which AFAIK aren’t in our Unicode data at present), and I think my code probably doesn’t cope with some of the more complex emoji cases.
Even then, I have a horrible suspicion that some terminals defer to the width information in the font, and in that case we just have to accept we’ll get it wrong in some cases.
I believe this was fixed by #2512
Yes, indeed.