ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

Wrong completion when file has emoji #159

Closed Klaster1 closed 7 years ago

Klaster1 commented 7 years ago

What happens: Weird completion results when document has emoji (commented or not). actual

const a = 'a'
const b = '🍆'
a.

Expected behavior: Same completion as on this image: expected

marijnh commented 7 years ago

The problem appears to be that editors, sanely, count positions in characters, but Tern, at the moment, counts in UTF16 units, so astral plane characters will count as two, and throw off all positions after them.

This is a bug in Tern, and it should be adjusted to treat positions received from and sent to the outside world as character offsets.

marijnh commented 7 years ago

Attached patch seems to solve the issue in Sublime Text. (Emacs is still broken because Emacs' JSON library seems to not be aware that astral plane characters exist.)

marijnh commented 7 years ago

Err, I meant patch https://github.com/ternjs/tern/commit/3cfb76a2734a840ce3543ffbe46825b44587a892

marijnh commented 7 years ago

(It does work in Emacs version 25, which fixes the JSON encoder.)