LineMarkerProvider multiple gutter icons

Hi Community,

I implemented a LineMarkerProvider and it works fine, but if the user edits the line which is marked the gutter icon is shown multiple times.
The multiple icons are removed if the user edits some other code in the file.

I followed thistutorial: http://confluence.jetbrains.com/display/IntelliJIDEA/Line+Marker+Provider

Is there a way to prevent this behavior?

Thanks in advance,
Markus



Attachment(s):
Gutter_Icons.png
11 comments
Comment actions Permalink

Hi Markus,

Are you passing the same element to builder.createLineMarkerInfo() that was passed to your collectNavigationMarkers() implementation?

0
Comment actions Permalink

Yes I do.

Is it wrong?

0
Comment actions Permalink

No, this is correct. To which element are you trying to attach the line marker?


0
Comment actions Permalink

I tried to attach it to a PsiClass and to a list of PsiMethods depending on a comment in the marked line

0
Comment actions Permalink

Please try to attach it to the class's or method's name identifier (the result of calling getNameIdentifier()) instead. Among other reasons, this is important because it places the icon correctly when the declaration is split over multiple lines.

0
Comment actions Permalink

This should be correct, right?

create(AllIcons.Ide.HectorSyntax).setTargets(psiClass.getNameIdentifier()).setTooltipText("Navigate to link");
result.add(gutterIconBuilder.createLineMarkerInfo(element));


I still get the same behavior.

0
Comment actions Permalink

No, I don't mean changing the target, I mean changing the element on which the icon is displayed.

PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass != null && element == psiClass.getNameIdentifier()) {
...
result.add(gutterIconBuilder.createLineMarkerInfo(element));
}

0
Comment actions Permalink

Sorry but I don't understand what you mean.

Is the problem the element in this call: gutterIconBuilder.createLineMarkerInfo(element)?

My current implementation is this:

protected void collectNavigationMarkers(PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
     if (element instanceof PsiComment) {
        Project project = element.getProject();
        String comment = element.getText();

        if (comment.contains("link/:") && comment.contains(":/")) {
            int startIndex = comment.indexOf("/:") + 2;
            int endIndex = comment.indexOf(":/");
      
            String className = comment.substring(startIndex, endIndex);

            PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));

            if (psiClass != null) {
                 NavigationGutterIconBuilder<PsiElement> gutterIconBuilder = NavigationGutterIconBuilder.create(AllIcons.Ide.HectorSyntax).setTargets(psiClass).setTooltipText("Navigate to link");
                 result.add(gutterIconBuilder.createLineMarkerInfo(element));
            }
        }
    }
}



Could you provide more info please?

0
Comment actions Permalink

Please help me the code I posted doesn't work, because I still get the duplicate gutter icons.

0
Comment actions Permalink

I don't see anything wrong with this code. It looks like you may be running into an IntelliJ issue with not being able to correctly match PSI elements when a file is reparsed. Could you please file a YouTrack issue with a link to your plugin and some steps to reproduce? Thanks!

0

Please sign in to leave a comment.