package com.cedricziel.idea.typo3.codeInsight;

import com.cedricziel.idea.typo3.TYPO3CMSIcons;
import com.cedricziel.idea.typo3.index.RouteIndex;
import com.cedricziel.idea.typo3.psi.PhpElementsUtil;
import com.cedricziel.idea.typo3.routing.RouteStub;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider;
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

public class RouteLineMarkerProvider extends RelatedItemLineMarkerProvider {
    @Override
    protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {

        if (!(element instanceof StringLiteralExpression)) {
            return;
        }

        StringLiteralExpression literalExpression = (StringLiteralExpression) element;
        String value = literalExpression.getContents();

        if (value.isEmpty()) {
            return;
        }

        PsiElement methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
        if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getAjaxUrl") || PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "buildUriFromRoute")) {

            if (RouteIndex.hasRoute(element.getProject(), value)) {
                Collection<RouteStub> routes = RouteIndex.getRoute(element.getProject(), value);
                routes.forEach(def -> {
                    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder
                            .create(TYPO3CMSIcons.ROUTE_ICON);

                    result.add(builder.createLineMarkerInfo(element));
                });

            }
        }
    }
}

@@ -190,24 +190,78 @@
 ementsUtil;%0A
+import com.cedricziel.idea.typo3.routing.RouteHelper;%0A
 import com.c
@@ -950,16 +950,25 @@
 element,
+ @NotNull
  Collect
@@ -1818,16 +1818,144 @@
 ef -%3E %7B%0A
+                    PsiElement%5B%5D routeDefinitionElements = RouteHelper.getRouteDefinitionElements(element.getProject(), value);%0A
         
@@ -2105,17 +2105,229 @@
 TE_ICON)
-;
+%0A                            .setTargets(routeDefinitionElements);%0A%0A                    if (def.getPath() != null) %7B%0A                        builder.setTooltipTitle(%22Path: %22 + def.getPath());%0A                    %7D
 %0A%0A      

Fix RouteLineMarker by calling setTargets