|
4 | 4 | import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
5 | 5 | import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
|
6 | 6 | import com.intellij.navigation.GotoRelatedItem;
|
7 |
| -import com.intellij.openapi.util.Iconable; |
8 | 7 | import com.intellij.psi.PsiElement;
|
9 |
| -import com.intellij.psi.impl.ElementBase; |
| 8 | +import com.intellij.psi.PsiFile; |
| 9 | +import com.intellij.psi.util.PsiElementFilter; |
10 | 10 | import com.intellij.psi.util.PsiTreeUtil;
|
11 | 11 | import com.intellij.util.ConstantFunction;
|
12 | 12 | import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment;
|
13 | 13 | import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag;
|
14 | 14 | import com.jetbrains.php.lang.psi.elements.*;
|
15 | 15 | import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
|
16 |
| -import fr.adrienbrault.idea.symfony2plugin.Symfony2InterfacesUtil; |
17 | 16 | import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
|
18 | 17 | import fr.adrienbrault.idea.symfony2plugin.TwigHelper;
|
| 18 | +import fr.adrienbrault.idea.symfony2plugin.config.SymfonyPhpReferenceContributor; |
| 19 | +import fr.adrienbrault.idea.symfony2plugin.doctrine.EntityHelper; |
19 | 20 | import fr.adrienbrault.idea.symfony2plugin.routing.Route;
|
20 | 21 | import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper;
|
21 | 22 | import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil;
|
| 23 | +import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher; |
22 | 24 | import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
|
23 |
| -import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils; |
24 | 25 | import icons.TwigIcons;
|
25 | 26 | import org.jetbrains.annotations.NotNull;
|
26 | 27 | import org.jetbrains.annotations.Nullable;
|
| 28 | +import org.jetbrains.yaml.psi.YAMLFile; |
27 | 29 |
|
28 | 30 | import javax.swing.*;
|
29 | 31 | import java.util.*;
|
@@ -90,8 +92,19 @@ public LineMarkerInfo collect(PsiElement psiElement) {
|
90 | 92 | public static List<GotoRelatedItem> getGotoRelatedItems(Method method) {
|
91 | 93 | List<GotoRelatedItem> gotoRelatedItems = new ArrayList<GotoRelatedItem>();
|
92 | 94 |
|
93 |
| - attachRelatedTemplates(method, gotoRelatedItems); |
| 95 | + |
| 96 | + // inside method |
| 97 | + PsiElement[] methodParameter = PsiTreeUtil.collectElements(method, new PsiElementFilter() { |
| 98 | + @Override |
| 99 | + public boolean isAccepted(PsiElement psiElement) { |
| 100 | + return psiElement.getParent() instanceof ParameterList; |
| 101 | + } |
| 102 | + }); |
| 103 | + |
| 104 | + attachRelatedTemplates(method, methodParameter, gotoRelatedItems); |
94 | 105 | attachRelatedRoutes(method, gotoRelatedItems);
|
| 106 | + attachRelatedModels(method, methodParameter, gotoRelatedItems); |
| 107 | + |
95 | 108 | return gotoRelatedItems;
|
96 | 109 | }
|
97 | 110 |
|
@@ -120,7 +133,7 @@ private static void attachRelatedRoutes(PsiElement psiElement, List<GotoRelatedI
|
120 | 133 | }
|
121 | 134 | }
|
122 | 135 |
|
123 |
| - private static void attachRelatedTemplates(Method method, List<GotoRelatedItem> gotoRelatedItems) { |
| 136 | + private static void attachRelatedTemplates(Method method, PsiElement[] parameterValues, List<GotoRelatedItem> gotoRelatedItems) { |
124 | 137 |
|
125 | 138 | Set<String> uniqueTemplates = new HashSet<String>();
|
126 | 139 |
|
@@ -151,23 +164,46 @@ private static void attachRelatedTemplates(Method method, List<GotoRelatedItem>
|
151 | 164 | }
|
152 | 165 | }
|
153 | 166 |
|
154 |
| - // inside method |
155 |
| - for(MethodReference methodReference : PsiTreeUtil.findChildrenOfType(method, MethodReference.class)) { |
156 |
| - if(new Symfony2InterfacesUtil().isTemplatingRenderCall(methodReference)) { |
157 |
| - PsiElement templateParameter = PsiElementUtils.getMethodParameterPsiElementAt((methodReference).getParameterList(), 0); |
158 |
| - if(templateParameter != null) { |
159 |
| - String resolveString = PhpElementsUtil.getStringValue(templateParameter); |
160 |
| - if(resolveString != null && !uniqueTemplates.contains(resolveString)) { |
161 |
| - uniqueTemplates.add(resolveString); |
162 |
| - for(PsiElement templateTarget: TwigHelper.getTemplatePsiElements(method.getProject(), resolveString)) { |
163 |
| - gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(templateTarget, resolveString).withIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_LINE_MARKER)); |
164 |
| - } |
| 167 | + for(PsiElement psiElement: parameterValues) { |
| 168 | + MethodMatcher.MethodMatchParameter matchedSignature = MethodMatcher.getMatchedSignatureWithDepth(psiElement, SymfonyPhpReferenceContributor.TEMPLATE_SIGNATURES); |
| 169 | + if (matchedSignature != null) { |
| 170 | + String resolveString = PhpElementsUtil.getStringValue(psiElement); |
| 171 | + if(resolveString != null && !uniqueTemplates.contains(resolveString)) { |
| 172 | + uniqueTemplates.add(resolveString); |
| 173 | + for(PsiElement templateTarget: TwigHelper.getTemplatePsiElements(method.getProject(), resolveString)) { |
| 174 | + gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(templateTarget, resolveString).withIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_LINE_MARKER)); |
165 | 175 | }
|
166 | 176 | }
|
167 | 177 | }
|
| 178 | + |
168 | 179 | }
|
169 | 180 |
|
170 | 181 |
|
171 | 182 | }
|
172 | 183 |
|
| 184 | + private static void attachRelatedModels(Method method, PsiElement[] parameterValues, List<GotoRelatedItem> gotoRelatedItems) { |
| 185 | + |
| 186 | + for(PsiElement psiElement: parameterValues) { |
| 187 | + MethodMatcher.MethodMatchParameter matchedSignature = MethodMatcher.getMatchedSignatureWithDepth(psiElement, SymfonyPhpReferenceContributor.REPOSITORY_SIGNATURES); |
| 188 | + if (matchedSignature != null) { |
| 189 | + String resolveString = PhpElementsUtil.getStringValue(psiElement); |
| 190 | + if(resolveString != null) { |
| 191 | + for(PsiElement templateTarget: EntityHelper.getModelPsiTargets(method.getProject(), resolveString)) { |
| 192 | + |
| 193 | + // we can provide targets to model config and direct class targets |
| 194 | + if(templateTarget instanceof PsiFile) { |
| 195 | + gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(templateTarget, resolveString).withIcon(templateTarget.getIcon(0), Symfony2Icons.SYMFONY_LINE_MARKER)); |
| 196 | + } else { |
| 197 | + // @TODO: we can resolve for model types and provide icons, but not for now |
| 198 | + gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(templateTarget, resolveString).withIcon(Symfony2Icons.DOCTRINE, Symfony2Icons.SYMFONY_LINE_MARKER)); |
| 199 | + } |
| 200 | + |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + } |
| 206 | + |
| 207 | + } |
| 208 | + |
173 | 209 | }
|
0 commit comments