gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
18k stars 751 forks source link

LSP ranges are incorrect when line contains multi-codepoint grapheme clusters #3628

Open joshi-monster opened 2 months ago

joshi-monster commented 2 months ago

The string is "क्षि", or "\u{0915}\u{094D}\u{0937}\u{093F}".

image

From the looks of it it actually just uses the byte/code unit count.

Tested with Gleam v1.4.1, in VSCode, Zed and Helix :purple_heart:

lpil commented 1 month ago

Thank you. I expect this'll be due to LSP using utf-16 and we're using utf-8.

aaron-loa commented 1 month ago

Hello. I looked a bit into this. Supposedly by setting the position_encoding type to UTF-8 the problem should be solved. After specifying the encoding it works correctly with editors that support UTF-8 encoding, like neovim. But it doesn't work with vscode. This is the error I get: Error: Unsupported position encoding (utf-8) received from server Gleam Language Server

Not sure about zed, I can't figure out how to change the path of the gleam language server to use my local binary.

Hovering is also affected by this problem, probably everything that interacts with positions. I will try to look more into what can be done this week. But from a quick skimming through, a lot of things need to be changed :smile:

lpil commented 1 month ago

Thank you @aaron-loa !!