I am trying to develop my own language plugin for IntelliJ using the Grammar-Kit plugin. I can easily highlight syntax highlighting for certain tokens, but I canβt figure out how to highlight at the level of an element or parent marker.
Here's a quick and dirty example language - https://github.com/carymrobbins/intellij-plugin-example
Decision
As @ignatov suggests, extend the Annotator class and register it in plugin.xml . In the example below, we highlight the command elements by defining a visitCommand method.
public class SimpleAnnotator implements Annotator { @Override public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) { element.accept(new SimpleVisitor() { @Override public void visitCommand(@NotNull SimpleCommand o) { super.visitCommand(o); setHighlighting(o, holder, SimpleSyntaxHighlighter.COMMAND); } }); } private static void setHighlighting(@NotNull PsiElement element, @NotNull AnnotationHolder holder, @NotNull TextAttributesKey key) { holder.createInfoAnnotation(element, null).setEnforcedTextAttributes(TextAttributes.ERASE_MARKER); holder.createInfoAnnotation(element, null).setEnforcedTextAttributes( EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key)); } }
source share