Missing highlight when multiple annotators applied to same TextRange?

Answered

Hi, all

I registered two annotators for my custom language plugin, one used for color highlighting and another for syntax error highlighting.

But these two annotators can't work together. If there is an element that shoud be highlighted by both of them, only syntax annotator worked.

this is how it looks like in Java: both color and syntax annotator worked:

but in my plugin, unfortunately, only syntax error annotator worked (the second @Override annotation should be highlighted with bule color too):

As for the color highlight annotator, I use

holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(range)
.textAttributes(key)
.create();

and for the syntax highlight annotator, I use

holder.newAnnotation(HighlightSeverity.ERROR, message)
.range(range)
.create();

Is there any way could help me solve this? Thanks.

0
5 comments

1) there is no order when executing Annotators, so results are by default "unpredictable"

2) text attributes will be merged only for same-level annotations (e.g. both "INFORMATION"). for this case, ERROR "wins" over "INFORMATION"

You may want to convert highlighting-only annotator to use com.intellij.codeHighlighting.TextEditorHighlightingPass

0

I did some debug and found that's because when error highlight happens, param "skipParentSet" of com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass#runVisitors contains the parent PsiElement that should be highlighted. In this case, the parent is excatly "@Override"......

Also you can see my keyword "class" in "class a" is not highlighted too.

Is com.intellij.codeHighlighting.TextEditorHighlightingPass able to solve this?

Or I can set forceHighlightParents to true with com.intellij.highlightRangeExtension point?

0

Sorry for delay. Did you find a working solution now? If not, what did you try?

0

I've solved this by using "HighlightInfoType.SYMBOL_TYPE_SEVERITY" in my syntax highlight annotator.

Thanks anyway :)

0

Thank you for posting your fix using HighlightInfoType.SYMBOL_TYPE_SEVERITY! That solved the same problem for me too.

0

Please sign in to leave a comment.