Closed
Description
Are there plans to add / improve support for encoding position offsets using UTF-8?
I would much prefer to use UTF-8 as the encoding for the position offsets. There is an extension to the LSP which is now supported by projects such as rust-analyzer. Are there plans to support this capability in the VSCode client?
Metadata
Metadata
Assignees
Labels
No labels
Activity
dbaeumer commentedon Mar 1, 2021
Support for VS Code client libs well happen when support for encoding negotiation will come to the protocol (see microsoft/language-server-protocol#376)
Please be aware that this will be a capability and there might still be clients/servers out there that might not support utf8.
I will close this as a dup of microsoft/language-server-protocol#376
The extension you are pointing to is Rust specific and is currently not part of the official specification.
dbaeumer commentedon Mar 1, 2021
Please ping if you think this issue should stay open.
alexrp commentedon Jul 28, 2022
Dirk Bäumer (@dbaeumer)
It looks like this support has now shipped in LSP 3.17.0. I am about to implement a language server and was hoping to only need to support UTF-8, so I just wanted to ask what the status is for supporting it in the client?
dbaeumer commentedon Aug 3, 2022
As mention in the specification the support for different encodings is, for performance reasons, better done on the server side than on the client side.
alexrp commentedon Aug 3, 2022
Can you clarify what you mean? I don't quite understand what conversion you're referring to.
I have source documents in UTF-8 form and I would like to implement my server in terms of UTF-8, but I can only do so if the client also speaks UTF-8 - which then means there should be no conversion necessary. My understanding is that that's the entire point of the offset encoding negotiation feature.
dbaeumer commentedon Aug 3, 2022
The encoding is not about the encoding of the characters on disk. It is about positions (line, character) in the file. The values for character assume that the string is represented in memory in utf-16 or utf-8. See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocuments for clarification.
alexrp commentedon Aug 3, 2022
OK, there was a misunderstanding there on my part. 🙂 I would indeed need to convert the document to UTF-8 when the client sends it over. But that's not the part I was actually referring to.
This client library only announces support for UTF-16 positions currently:
vscode-languageserver-node/client/src/common/client.ts
Line 1717 in 64156c6
As far as I understand, this means that when implementing my language server, I am essentially forced to use the UTF-16 document string sent by the client and do everything in terms of UTF-16 positions/ranges. So even if I convert the document to UTF-8, it wouldn't do me much good when it comes time to actually reply.
I think that's what this issue was about originally, too, hence why I posted here.
dbaeumer commentedon Aug 3, 2022
No, you could also only convert the character offset on a line and keep the document in uft-8 on the server. The line part of a position is actually encoding independent. But it forces you to split the document into lines on the server.
RblSb commentedon Nov 16, 2022
Can this be reopened to support positions in utf8?
This would be very handy, so every client will not need to convert utf16 offsets to utf8 for yourself, by char to char file iteration.