eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
582 stars 141 forks source link

Provide SemanticTokensLegend#encode method to perform encoding according to standard #769

Open laeubi opened 9 months ago

laeubi commented 9 months ago

I'm currently try to use getting some basic syntax highlights with SemanticTokensLegend / org.eclipse.lsp4j.services.TextDocumentService.semanticTokensFull(SemanticTokensParams) due to the specification this requires a non trivial transformation of types/modifiers/locations into a stream of ints.

To ease implementation (and add validation) I think it would be usefull to have a method in SemanticTokensLegend that helps in encoding things for example returning an IntStream and taking the keyword, the modifier and a location as input.

This method can the for example fail if invalid token types are send and so on.

pisv commented 9 months ago

Sounds like a good idea to me. However, from the API point of view, I would rather suggest adding the following methods to the SemanticTokensLegend:

    int encodeTokenType(String tokenType)
    int encodeTokenModifiers(Set<String> tokenModifiers)
    String decodeTokenType(int tokenType)
    Set<String> decodeTokenModifiers(int tokenModifiers)

@laeubi Would you like to submit a PR for that?