miniblog.

← Back to all posts
25
In LSP, a position is represented as a line number and a column offset (in Unicode code units): https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position This is pretty elegant. You'll get the correct line regardless of encoding bugs, and the editor already knows the line number so it's cheap to compute.

5 Comments

@fogti LSP 3.17 has improved the situation with encoding a whole bunch. Previously the spec assumed UTF-16, which was harder to work with.
@wilfredh the issue with implementation is that while the editor can choose the encoding, the server encoding for both utf-32 and utf-8 are optional. So most editors implement shenanigans to support offsets in utf-16 to be compliant with all servers while the storage unit of the editor is either utf-32 or utf-8.
@wilfredh but you're right, even if the wrong encoding is choosen, the failure is user recoverable and the blast radius is contained within a single line.