|
26 | 26 | import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
|
27 | 27 | import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
|
28 | 28 | import fr.adrienbrault.idea.symfony2plugin.dic.RelatedPopupGotoLineMarker;
|
| 29 | +import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.TwigExtendsStubIndex; |
29 | 30 | import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.TwigIncludeStubIndex;
|
30 | 31 | import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil;
|
31 | 32 | import fr.adrienbrault.idea.symfony2plugin.twig.loade
8000
r.FileImplementsLazyLoader;
|
32 | 33 | import fr.adrienbrault.idea.symfony2plugin.twig.loader.FileOverwritesLazyLoader;
|
33 | 34 | import fr.adrienbrault.idea.symfony2plugin.twig.utils.TwigBlockUtil;
|
| 35 | +import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils; |
34 | 36 | import icons.TwigIcons;
|
35 | 37 | import org.apache.commons.lang.StringUtils;
|
36 | 38 | import org.jetbrains.annotations.NotNull;
|
@@ -64,6 +66,11 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
|
64 | 66 | results.add(lineIncludes);
|
65 | 67 | }
|
66 | 68 |
|
| 69 | + LineMarkerInfo extending = attachExtends((TwigFile) psiElement); |
| 70 | + if(extending != null) { |
| 71 | + results.add(extending); |
| 72 | + } |
| 73 | + |
67 | 74 | // eg bundle overwrites
|
68 | 75 | LineMarkerInfo overwrites = attachOverwrites((TwigFile) psiElement);
|
69 | 76 | if(overwrites != null) {
|
@@ -113,6 +120,7 @@ private void attachController(@NotNull TwigFile twigFile, @NotNull Collection<?
|
113 | 120 | result.add(builder.createLineMarkerInfo(twigFile));
|
114 | 121 | }
|
115 | 122 |
|
| 123 | + @Nullable |
116 | 124 | private LineMarkerInfo attachIncludes(@NotNull TwigFile twigFile) {
|
117 | 125 | Collection<String> templateNames = TwigUtil.getTemplateNamesForFile(twigFile);
|
118 | 126 |
|
@@ -143,6 +151,37 @@ private LineMarkerInfo attachIncludes(@NotNull TwigFile twigFile) {
|
143 | 151 | return builder.createLineMarkerInfo(twigFile);
|
144 | 152 | }
|
145 | 153 |
|
| 154 | + @Nullable |
| 155 | + private LineMarkerInfo attachExtends(@NotNull TwigFile twigFile) { |
| 156 | + Collection<String> templateNames = TwigUtil.getTemplateNamesForFile(twigFile); |
| 157 | + |
| 158 | + boolean found = false; |
| 159 | + for(String templateName: templateNames) { |
| 160 | + Project project = twigFile.getProject(); |
| 161 | + |
| 162 | + Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance().getContainingFiles( |
| 163 | + TwigExtendsStubIndex.KEY, templateName, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), TwigFileType.INSTANCE) |
| 164 | + ); |
| 165 | + |
| 166 | + // stop on first target, we load them lazily afterwards |
| 167 | + if(containingFiles.size() > 0) { |
| 168 | + found = true; |
| 169 | + break; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + if(!found) { |
| 174 | + return null; |
| 175 | + } |
| 176 | + |
| 177 | + NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTED) |
| 178 | + .setTargets(new TemplateExtendsLazyTargets(twigFile.getProject(), twigFile.getVirtualFile())) |
| 179 | + .setTooltipText("Navigate to extends") |
| 180 | + .setCellRenderer(new MyFileReferencePsiElementListCellRenderer()); |
| 181 | + |
| 182 | + return builder.createLineMarkerInfo(twigFile); |
| 183 | + } |
| 184 | + |
146 | 185 | @Nullable
|
147 | 186 | private LineMarkerInfo attachOverwrites(@NotNull TwigFile twigFile) {
|
148 | 187 | Collection<PsiFile> targets = new ArrayList<>();
|
@@ -374,4 +413,25 @@ protected Icon getIcon(PsiElement psiElement) {
|
374 | 413 | return TwigIcons.TwigFileIcon;
|
375 | 414 | }
|
376 | 415 | }
|
| 416 | + |
| 417 | + /** |
| 418 | + * Find "extends" which are targeting the given template file |
| 419 | + */ |
| 420 | + private static class TemplateExtendsLazyTargets extends NotNullLazyValue<Collection<? extends PsiElement>> { |
| 421 | + @NotNull |
| 422 | + private final Project project; |
| 423 | + @NotNull |
| 424 | + private final VirtualFile virtualFile; |
| 425 | + |
| 426 | + TemplateExtendsLazyTargets(@NotNull Project project, @NotNull VirtualFile virtualFile) { |
| 427 | + this.project = project; |
| 428 | + this.virtualFile = virtualFile; |
| 429 | + } |
| 430 | + |
| 431 | + @NotNull |
| 432 | + @Override |
| 433 | + protected Collection<? extends PsiElement> compute() { |
| 434 | + return PsiElementUtils.convertVirtualFilesToPsiFiles(project, TwigUtil.getTemplatesExtendingFile(project, virtualFile)); |
| 435 | + } |
| 436 | + } |
377 | 437 | }
|
0 commit comments