Custom annotations constantly showing and disappearing
Hello, I have implemented given class:
class DuplicateAnnotator extends PsiElementVisitor implements Annotator
Inside there is given annotate() method:
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
try {
myHolder = holder;
psiElement.accept(this);
} finally {
myHolder = null;
}
}
I have also added given code inside visitFile() method:
myHolder.newAnnotation(HighlightSeverity.WARNING,
featureFile.getName() + ": lines " + firstLine + "-" + lastLine)
.range(steps.get(integerStringEntry.getKey()))
.create();
The problem is that my annotations are constantly disappearing and showing again. Is there anything I am missing in my code?
Edit: I also added flag that disallows visiting the same file multiple times. In that case annotations appear and then disappear so it does not resolve my problem.
请先登录再写评论。
Hi Patryk,
First, a common implementation of an
Annotatorchecks whether a passed element is of the type you want to annotate and does the job without an additional visitor. So in your case:In your case, you accept the visitor for each
psiElementpassed to the annotator, which executes visitor methods unnecessarily (default implementations, which are cheap, but still).Also, annotators should work on the lower possible element level and
PsiFileis the root. Annotating high-level elements may indeed cause blinking. Is it possible that you work on lower-level elements?