Semantic highlighting only works for the last line #636
-
I am trying to implement a semantic token provider for my language, here is a strange behaviour I got. A minimal reproducible example is available here, and the langium I use is 0.4.0. A snippet of the syntax and the semantic token provider is as follows:
import { SemanticTokenTypes } from 'vscode-languageserver';
import { AbstractSemanticTokenProvider, AstNode, SemanticTokenAcceptor } from 'langium';
import { isTypeDefinition } from './generated/ast';
export class MediatorGrammarSemanticTokenProvider extends AbstractSemanticTokenProvider {
protected highlightElement(node: AstNode, acceptor: SemanticTokenAcceptor): void {
if (isTypeDefinition(node)) {
acceptor({
node,
feature: 'alias',
type: SemanticTokenTypes.type
});
}
}
} Is there something wrong with my code? After comparing my code with the langium vscode extension's semantic token provider, I still cannot figure out why my implementation gets this strange behaviour while the langium vscode extension works well. I have done a search for semantic highlighting discussions and issues but did not get very useful information, and the only reference I have is the langium vscode extension. Any reference to semantic highlighting implementation via langium would also be very helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @luan-xiaokun, there's a minor issue in your grammar that prevents the semantic token provider from working correctly (and a lot of other services as well). Your AST model only consists of a single TypeDefinition, even though it parses multiple ones. You can easily fix this issue though:
|
Beta Was this translation helpful? Give feedback.
Hi @luan-xiaokun,
there's a minor issue in your grammar that prevents the semantic token provider from working correctly (and a lot of other services as well). Your AST model only consists of a single TypeDefinition, even though it parses multiple ones. You can easily fix this issue though: