Semantic Token support on Xtext LSP [message #1847709] |
Thu, 04 November 2021 09:42 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
|
Hi everyone,
I'm coming from this question in SO (stackoverflow.com/q/69820560/3222340).
We're currently testing a VS Code extension with an Xtext LS. So far all works fine. We're now at a point where we would like to go deeper on text highlighting (more precisely, semantic highlighting).
From the communication between the VS Code extension (client) and the Xtext LSP (server) I was able to see that Xtext's LSP implementation (LanguageServerImpl) does not offer a Semantic Token Provider as a server capability. That is mainly the reason why there are no requests of type 'textDocument/semanticTokens/*' from the client to the LSP.
I was able to enhance the Xtext project and create a new custom language server by extending the class "LanguageServerImpl", adding a Semantic Token Provider as capability and listening to the different RPC endpoints for semantic tokenization:
public class CustomLanguageServerImpl extends LanguageServerImpl {
...
@Override
protected ServerCapabilities createServerCapabilities(InitializeParams params) {
ServerCapabilities capabilities = super.createServerCapabilities(params);
// Create server capabilities for semantic tokens.
SemanticTokensWithRegistrationOptions options = new SemanticTokensWithRegistrationOptions();
List<String> tokenTypes = new ArrayList<String>();
tokenTypes.add(SemanticTokenTypes.Namespace);
...
List<String> tokenModifiers = new ArrayList<String>();
tokenModifiers.add(SemanticTokenModifiers.Declaration);
...
options.setLegend(new SemanticTokensLegend(tokenTypes, tokenModifiers));
options.setRange(false);
options.setFull(true);
capabilities.setSemanticTokensProvider(options);
return capabilities;
}
@Override
public CompletableFuture<SemanticTokens> semanticTokensFull(SemanticTokensParams params) {
...
}
@Override
public CompletableFuture<SemanticTokens> semanticTokensRange(SemanticTokensRangeParams params) {
...
}
@Override
public CompletableFuture<Either<SemanticTokens, SemanticTokensDelta>> semanticTokensFullDelta(
...
}
}
Surprisingly, now my VS Code extension is capable of sending 'textDocument/semanticTokens/*' requests to the LSP and I'm able to return hardcoded semantic tokens from the LSP.
My question are:
- Does Xtext provide logic to help implementing the methods that must return the semantic tokens? Similarly as Xtext provides already the logic for code completion, renaming, etc...
- If not, would it this mean that we need to create a logic that parses files to find these tokens?
Any kind of guidance on this aspect would be very helpful.
Kind regards.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03517 seconds