Skip to content

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

Description

@dpc00

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions