27
27
import fr .adrienbrault .idea .symfony2plugin .stubs .indexes .TwigExtendsStubIndex ;
28
28
import fr .adrienbrault .idea .symfony2plugin .stubs .indexes .TwigIncludeStubIndex ;
29
29
import fr .adrienbrault .idea .symfony2plugin .stubs .indexes .TwigMacroFromStubIndex ;
30
+ import fr .adrienbrault .idea .symfony2plugin .templating .dict .TemplateFileMap ;
30
31
import fr .adrienbrault .idea .symfony2plugin .templating .util .TwigUtil ;
31
32
import icons .TwigIcons ;
32
33
import org .jetbrains .annotations .NotNull ;
33
34
import org .jetbrains .annotations .Nullable ;
34
35
36
+ import javax .swing .*;
35
37
import java .util .*;
36
38
37
39
public class TwigControllerLineMarkerProvider implements LineMarkerProvider {
38
40
39
41
40
- private Map < String , VirtualFile > templateMapCache = null ;
42
+ private TemplateFileMap templateMapCache = null ;
41
43
42
44
@ Override
43
45
public void collectSlowLineMarkers (@ NotNull List <PsiElement > psiElements , @ NotNull Collection <LineMarkerInfo > results ) {
@@ -78,6 +80,12 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
78
80
if (lineFromInclude != null ) {
79
81
results .add (lineFromInclude );
80
82
}
83
+
84
+ // attach parent includes goto
85
+ LineMarkerInfo overwrites = attachOverwrites ((TwigFile ) psiElement );
86
+ if (overwrites != null ) {
87
+ results .add (overwrites );
88
+ }
81
89
}
82
90
83
91
}
@@ -110,12 +118,13 @@ private void attachController(@NotNull TwigFile twigFile, @NotNull Collection<?
110
118
111
119
private LineMarkerInfo attachIncludes (TwigFile twigFile ) {
112
120
121
+ TemplateFileMap files = getTemplateFilesByName (twigFile .getProject ());
113
122
114
123
final Collection <PsiFile > targets = new ArrayList <PsiFile >();
115
- for (Map . Entry < String , VirtualFile > entry : TwigUtil .getTemplateName (twigFile ). entrySet ( )) {
124
+ for (String templateName : TwigUtil .getTemplateName (twigFile . getVirtualFile (), files )) {
116
125
117
126
final Project project = twigFile .getProject ();
118
- FileBasedIndexImpl .getInstance ().getFilesWithKey (TwigIncludeStubIndex .KEY , new HashSet <String >(Arrays .asList (entry . getKey () )), new Processor <VirtualFile >() {
127
+ FileBasedIndexImpl .getInstance ().getFilesWithKey (TwigIncludeStubIndex .KEY , new HashSet <String >(Arrays .asList (templateName )), new Processor <VirtualFile >() {
119
128
@ Override
120
129
public boolean process (VirtualFile virtualFile ) {
121
130
PsiFile psiFile = PsiManager .getInstance (project ).findFile (virtualFile );
@@ -134,29 +143,60 @@ public boolean process(VirtualFile virtualFile) {
134
143
return null ;
135
144
}
136
145
137
- Map <String , VirtualFile > files = getTemplateFilesByName (twigFile .getProject ());
138
146
139
147
List <GotoRelatedItem > gotoRelatedItems = new ArrayList <GotoRelatedItem >();
140
148
for (PsiElement blockTag : targets ) {
141
- gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
149
+ gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files . getTemplates () , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
142
150
}
143
151
144
152
return getRelatedPopover ("Implementations" , "Impl: " ,twigFile , gotoRelatedItems );
145
153
146
154
}
147
155
148
- private Map <String , VirtualFile > getTemplateFilesByName (Project project ) {
149
- return this .templateMapCache == null ? this .templateMapCache = TwigHelper .getTemplateFilesByName (project , true , false ) : this .templateMapCache ;
156
+ @ Nullable
157
+ private LineMarkerInfo attachOverwrites (@ NotNull TwigFile twigFile ) {
158
+
159
+ Collection <PsiFile > targets = new ArrayList <PsiFile >();
160
+
161
+ TemplateFileMap files = getTemplateFilesByName (twigFile .getProject ());
162
+
163
+ for (String templateName : TwigUtil .getTemplateName (twigFile .getVirtualFile (), files )) {
164
+ for (PsiFile psiFile : TwigHelper .getTemplatePsiElements (twigFile .getProject (), templateName )) {
165
+ if (!psiFile .getVirtualFile ().equals (twigFile .getVirtualFile ()) && !targets .contains (psiFile )) {
166
+ targets .add (psiFile );
167
+ }
168
+ }
169
+ }
170
+
171
+ if (targets .size () == 0 ) {
172
+ return null ;
173
+ }
174
+
175
+ List <GotoRelatedItem > gotoRelatedItems = new ArrayList <GotoRelatedItem >();
176
+ for (PsiElement blockTag : targets ) {
177
+ gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (
178
+ blockTag ,
179
+ TwigUtil .getPresentableTemplateName (files .getTemplates (), blockTag , true )
180
+ ).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_OVERWRITE ));
181
+ }
182
+
183
+ return getRelatedPopover ("Overwrites" , "Overwrite" , twigFile , gotoRelatedItems , Symfony2Icons .TWIG_LINE_OVERWRITE );
184
+ }
185
+
186
+ private TemplateFileMap getTemplateFilesByName (Project project ) {
187
+ return this .templateMapCache == null ? this .templateMapCache = TwigHelper .getTemplateMap (project , true , false ) : this .templateMapCache ;
150
188
}
151
189
152
190
@ Nullable
153
191
private LineMarkerInfo attachFromIncludes (TwigFile twigFile ) {
154
192
193
+ TemplateFileMap files = getTemplateFilesByName (twigFile .getProject ());
194
+
155
195
final Collection <PsiFile > targets = new ArrayList <PsiFile >();
156
- for (Map . Entry < String , VirtualFile > entry : TwigUtil . getTemplateName (twigFile ). entrySet ( )) {
196
+ for (String templateName : files . getNames (twigFile . getVirtualFile () )) {
157
197
158
198
final Project project = twigFile .getProject ();
159
- FileBasedIndexImpl .getInstance ().getFilesWithKey (TwigMacroFromStubIndex .KEY , new HashSet <String >(Arrays .asList (entry . getKey () )), new Processor <VirtualFile >() {
199
+ FileBasedIndexImpl .getInstance ().getFilesWithKey (TwigMacroFromStubIndex .KEY , new HashSet <String >(Arrays .asList (templateName )), new Processor <VirtualFile >() {
160
200
@ Override
161
201
public boolean process (VirtualFile virtualFile ) {
162
202
PsiFile psiFile = PsiManager .getInstance (project ).findFile (virtualFile );
@@ -175,17 +215,19 @@ public boolean process(VirtualFile virtualFile) {
175
215
return null ;
176
216
}
177
217
178
- Map <String , VirtualFile > files = getTemplateFilesByName (twigFile .getProject ());
179
-
180
218
List <GotoRelatedItem > gotoRelatedItems = new ArrayList <GotoRelatedItem >();
181
219
for (PsiElement blockTag : targets ) {
182
- gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
220
+ gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files . getTemplates () , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
183
221
}
184
222
185
- return getRelatedPopover ("Implementations" , "Impl: " , twigFile , gotoRelatedItems );
223
+ return getRelatedPopover ("Implementations" , "Impl: " , twigFile , gotoRelatedItems );
186
224
}
187
225
188
226
private LineMarkerInfo getRelatedPopover (String singleItemTitle , String singleItemTooltipPrefix , PsiElement lineMarkerTarget , List <GotoRelatedItem > gotoRelatedItems ) {
227
+ return getRelatedPopover (singleItemTitle , singleItemTooltipPrefix , lineMarkerTarget , gotoRelatedItems , PhpIcons .IMPLEMENTED );
228
+ }
229
+
230
+ private LineMarkerInfo getRelatedPopover (String singleItemTitle , String singleItemTooltipPrefix , PsiElement lineMarkerTarget , List <GotoRelatedItem > gotoRelatedItems , Icon icon ) {
189
231
190
232
// single item has no popup
191
233
String title = singleItemTitle ;
@@ -196,7 +238,7 @@ private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleIt
196
238
}
197
239
}
198
240
199
- return new LineMarkerInfo <PsiElement >(lineMarkerTarget , lineMarkerTarget .getTextOffset (), PhpIcons . IMPLEMENTED , 6 , new ConstantFunction <PsiElement , String >(title ), new RelatedPopupGotoLineMarker .NavigationHandler (gotoRelatedItems ));
241
+ return new LineMarkerInfo <PsiElement >(lineMarkerTarget , lineMarkerTarget .getTextOffset (), icon , 6 , new ConstantFunction <PsiElement , String >(title ), new RelatedPopupGotoLineMarker .NavigationHandler (gotoRelatedItems ));
200
242
}
201
243
202
244
@ Nullable
@@ -207,10 +249,10 @@ private LineMarkerInfo attachBlockImplements(final PsiElement psiElement) {
207
249
return null ;
208
250
}
209
251
210
- Map < String , VirtualFile > files = getTemplateFilesByName (psiElement .getProject ());
252
+ TemplateFileMap files = getTemplateFilesByName (psiElement .getProject ());
211
253
212
254
List <PsiFile > twigChild = new ArrayList <PsiFile >();
213
- getTwigChildList (files , psiFile , twigChild , 8 );
255
+ getTwigChildList (files . getTemplates () , psiFile , twigChild , 8 );
214
256
215
257
if (twigChild .size () == 0 ) {
216
258
return null ;
@@ -236,7 +278,7 @@ public boolean isAccepted(PsiElement psiElement) {
236
278
237
279
List <GotoRelatedItem > gotoRelatedItems = new ArrayList <GotoRelatedItem >();
238
280
for (PsiElement blockTag : blockTargets ) {
239
- gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
281
+ gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files . getTemplates () , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
240
282
}
241
283
242
284
return getRelatedPopover ("Implementations" , "Impl: " , psiElement , gotoRelatedItems );
@@ -251,11 +293,9 @@ private LineMarkerInfo attachBlockOverwrites(PsiElement psiElement) {
251
293
return null ;
252
294
}
253
295
254
- Map <String , VirtualFile > files = getTemplateFilesByName (psiElement .getProject ());
255
-
256
296
List <GotoRelatedItem > gotoRelatedItems = new ArrayList <GotoRelatedItem >();
257
297
for (PsiElement blockTag : blocks ) {
258
- gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (files , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
298
+ gotoRelatedItems .add (new RelatedPopupGotoLineMarker .PopupGotoRelatedItem (blockTag , TwigUtil .getPresentableTemplateName (getTemplateFilesByName ( psiElement . getProject ()). getTemplates () , blockTag , true )).withIcon (TwigIcons .TwigFileIcon , Symfony2Icons .TWIG_LINE_MARKER ));
259
299
}
260
300
261
301
// single item has no popup
0 commit comments