Skip to content

UTF-8 Support #748

Closed
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?

Activity

  1. dbaeumer commented on Mar 1, 2021

    @dbaeumer
    Member

    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.

  2. dbaeumer commented on Mar 1, 2021

    @dbaeumer
    Member

    Please ping if you think this issue should stay open.

  3. alexrp commented on Jul 28, 2022

    @alexrp

    Dirk Bäumer (@dbaeumer)

    Support for VS Code client libs well happen when support for encoding negotiation will come to the protocol (see microsoft/language-server-protocol#376)

    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?

  4. dbaeumer commented on Aug 3, 2022

    @dbaeumer
    Member

    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.

  5. alexrp commented on Aug 3, 2022

    @alexrp

    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.

  6. dbaeumer commented on Aug 3, 2022

    @dbaeumer
    Member

    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.

  7. alexrp commented on Aug 3, 2022

    @alexrp

    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:

    generalCapabilities.positionEncodings = ['utf-16'];

    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.

  8. dbaeumer commented on Aug 3, 2022

    @dbaeumer
    Member

    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.

    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.

  9. RblSb commented on Nov 16, 2022

    @RblSb

    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.

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