I'm currently testing how to create a VS Code extension that would allow me to write files using my own DSL defined in Xtext (*.sample
). So far I've been able to create the VS Code extension and use it:
- Open a file (
*.sample
) and load the extension. - See syntax errors, text prediction, renaming, etc (communication with Xtext LS works fine).
- See syntax color highlighting by means of a TextMate grammar and a couple of VS Code UI themes I've created.
Now I would like to go a step further and enable semantic highlighting. So far I understand that this is a capability of the LS (see LSP specification 3.16) and the highlighting information comes from the server. However the only information I can find about semantic highlighting and VS Code is the creation of a DocumentSemanticTokensProvider
in the VS Code extension, that is, client side (see VS Code documentation). As I understand the Semantic Token Provider returns the tokens with its classification (class, namespace, enum, ...
) and modifier (declaration, declaration, ...
). From my understanding this would imply some file analysis on the client side, which from my point of view is not the way to go.
On the other side, I'm not able to find any documentation on how to "activate" the semantic highlighting in the server side (Xtext) so the semantic tokens are returned when the client requests them.
As you can see I have lots of doubts on how the semantic highlighting would work in my scenario. Therefore I would like to ask the following questions.
- Where do I need to define the logic that decides which are the semantic tokens of a file?
- How does the VS Code extension triggers the calculation of semantic tokens in the server?
Any other comment on whether my assumptions are correct (or not) are welcome.
Many thanks in advance.