SublimeLinter-coffee icon indicating copy to clipboard operation
SublimeLinter-coffee copied to clipboard

Error column is off by one for each emoji earlier on the line (CoffeeScript counts UTF-16 units)

Open dpc00 opened this issue 2 months ago • 1 comments

Error column is off by one for each emoji (non-BMP character) earlier on the line: CoffeeScript counts UTF-16 units

Version: SublimeLinter-coffee 3.x from Package Control, coffeescript 2.7.0, CoffeeScript syntax package, SublimeLinter 4, Sublime Text 4215 on Windows. Reproduced in a clean install.

b.coffee (UTF-8):

s = "😀😀" ; foo bar baz(

coffee --compile --stdio < b.coffee:

[stdin]:1:25: error: missing )
s = "😀😀" ; foo bar baz(
                        ^

The error is at the ( of baz(, which is character 23 (1-based) of the line as Sublime counts, but CoffeeScript says 25, because each 😀 (U+1F600) is two UTF-16 code units in JavaScript strings. In Sublime the highlight lands two characters too far to the right, on the line break at the end of the line (start 23, expected 22, 0-based).

The same with one emoji, a.coffee:

x = "é😀" + (1 +
y = 2
[stdin]:1:13: error: missing )

The error is at the ( (character 12 in Sublime), and the plugin highlights the 1 after it (start 12, expected 11, 0-based). é (one UTF-16 unit) does not shift anything.

The col group of the regex is used as it is. Suggested fix: override reposition_match(self, line, col, m, vv), take the line via vv.select_line(line), and convert the UTF-16 offset to a character offset by walking the line and counting every character above U+FFFF twice. The same fix was just merged for SublimeLinter-xmllint (bytes) and is proposed for SublimeLinter-tslint and -javac (UTF-16). I can prepare a PR if you would like one.

dpc00 avatar Sep 29 '26 23:09 dpc00

Ack, however, in the two-emoji example, the raw offset is wrong by two, I think. You can make a PR.

kaste avatar Sep 30 '26 07:09 kaste