Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Semantic Token support on Xtext LSP
Semantic Token support on Xtext LSP [message #1847709] Thu, 04 November 2021 09:42 Go to next message
Alejandro González is currently offline Alejandro GonzálezFriend
Messages: 7
Registered: November 2021
Location: Aachen, Germany
Junior Member
Hi everyone,

I'm coming from this question in SO (

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 {


	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>();

		List<String> tokenModifiers = new ArrayList<String>();
                options.setLegend(new SemanticTokensLegend(tokenTypes, tokenModifiers));


		return capabilities;

	public CompletableFuture<SemanticTokens> semanticTokensFull(SemanticTokensParams params) {

	public CompletableFuture<SemanticTokens> semanticTokensRange(SemanticTokensRangeParams params) {

	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.
Re: Semantic Token support on Xtext LSP [message #1847720 is a reply to message #1847709] Thu, 04 November 2021 13:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14261
Registered: July 2009
Senior Member
no. nobody contributed that feature yet. you are welcome to do so

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous not updating
Next Topic:[Xtext] Grammar - Enhancing the infered model for language expressions
Goto Forum:

Current Time: Thu May 19 13:26:31 GMT 2022

Powered by FUDForum. Page generated in 0.01869 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top