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: 1
Registered: November 2021
Junior Member
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.
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: 14113
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: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:log4j.properties not updating
Next Topic:[Xtext] Grammar - Enhancing the infered model for language expressions
Goto Forum:
  


Current Time: Thu Jan 27 12:18:43 GMT 2022

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

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

Back to the top