LineMarkerProvider: Duplicate Icons inside the Gutter when user edits the text of it's Anchor-Element.

The following code, originally taken from http://confluence.jetbrains.com/display/IntelliJIDEA/Line+Marker+Provider (Custom Language Tutorial) and modified, generates duplicate Icons in the Gutter-Area of the Editor if
the user edits the Text behind the "hello" inside the DocComment.

import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider;
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.icons.AllIcons;
import com.intellij.psi.PsiElement;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

/**
*
* hello Changing this line will cause duplicate Icons in the Gutter, if the LineMarkerProvider below is running
*
*/
public class DuplicateLineMarkerProvider extends RelatedItemLineMarkerProvider {
    
    @Override
    protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
        if (element instanceof PsiDocComment) {
            PsiDocComment docComment = (PsiDocComment) element;
            if (docComment.getText().toLowerCase().contains("hello")) {
                NavigationGutterIconBuilder<PsiElement> builder =
                        NavigationGutterIconBuilder.create(AllIcons.General.Error).setTarget(element.getParent());
                //Using the whole PsiDocComment as Location-Anchor
                result.add(builder.createLineMarkerInfo(element));
            }
        }
    }
}



It's not the actual code i'm working with, but the smallest possible piece of code I found which duplicates the problem.
I'm guessing it has something to do with the text of the Anchor-Element (element above) being able to change, preventing it to register as duplicate or invalidate the cached Icon directly.

My actual code shows an Icon when a certain DocTag is found inside a DocComment, but I have to use the whole DocComment as Anchor,
because I want my Icon to be shown even if the DocComment is folded.

Is this a bug in IntelliJ, do I need to manually check for possible duplicates myself?

Message was edited by: Peter Schmitz Simplified example code a bit more.

2 comments
Comment actions Permalink

(push)

Can someone confirm this behaviour? I don't want to open a new Bugtracker entry before I know if it's solely on my side.

I already found several similiar Entries in the Bugtracker, but most of them have been fixed individually, but I don't really see how the fix (or workaround?) .works.

I noticed however, that sometimes redundant Icons disappear from the gutter, but I haven't been able to locate the circumstance / trigger for it.

Thanks,
Peter



Attachment(s):
2014-01-30_Duplicate_Gutter_Icons.png
0
Comment actions Permalink

Same issue here.

The Icons are only removed if the user edits other parts of code. Is there any way to resolve this problem?

Markus



Attachment(s):
Gutter_Icons.png
0

Please sign in to leave a comment.