I am getting multiple tooltips when using typedhandler+annotator

Following is the code I wrote
public class SimpleAnnotator implements Annotator {
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
SyntaxHighlighter syntaxHighlighter= new SyntaxHighlighter();
if (!syntaxHighlighter.annotateoffsets.isEmpty()) {
for (int i = 1; i < syntaxHighlighter.annotateoffsets.size() + 1; i++) {
int startOffset = syntaxHighlighter.annotateoffsets.get(i).get(0);
int endOffset = syntaxHighlighter.annotateoffsets.get(i).get(1);
String tooltip = syntaxHighlighter.tooltips.get(i-1);
TextRange range = new TextRange(startOffset, endOffset);
Annotation annotation = annotationHolder.createErrorAnnotation(range, "");
annotation.setTooltip(tooltip);
}
}
}
}
Please sign in to leave a comment.
Looks like `syntaxHighlighter.annotateoffsets` of yours contains zillions of items.
Even more troubling is that this annotate() method ignores psiElement parameter.
Generally Annotators should process PSI element arguments as small as possible (e.g. ignore PsiMethod passed but process its PsiIdentifier) and immediately call AnnotationHolder.createXXX() for that small range.