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: 8
Registered: November 2021
Location: Aachen, Germany
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 messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no. nobody contributed that feature yet. you are welcome to do so

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Semantic Token support on Xtext LSP [message #1854897 is a reply to message #1847709] Fri, 16 September 2022 15:30 Go to previous messageGo to next message
Laila Ikki is currently offline Laila IkkiFriend
Messages: 1
Registered: September 2022
Junior Member
Hi,

Thank you for your post. I was just wondering where exactly you added these new server capabilities. I'm customizing the VSCode Xtext Sprotty Example (https://github.com/TypeFox/vscode-xtext-sprotty-example/tree/main/extension), and I'd like to enable custom semantic highlighting based on EObject. I just don't know where I need to go to extend the language server implementation to include that. If you could offer any guidance or point me in any direction, I would really appreciate it. Thanks so much!
Re: Semantic Token support on Xtext LSP [message #1854905 is a reply to message #1854897] Sat, 17 September 2022 05:40 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the languageserverimpl class is managed by ServerModule in guice that is used by ServerLauncher.
Meanwhile ruben is working on the topic. https://github.com/eclipse/xtext-core/pull/1960
so you might help there


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext & Xtend for Java 17: please help testing
Next Topic:Grammar with a post-fix operator
Goto Forum:
  


Current Time: Fri Apr 19 01:35:17 GMT 2024

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

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

Back to the top