@@ -169,22 +169,27 @@ public static Collection<TwigTypeContainer> resolveTwigMethodName(@NotNull PsiEl
169
169
*
170
170
* "@var foo \Foo"
171
171
*/
172
- private static Map <String , String > findInlineStatementVariableDocBlock (PsiElement psiInsideBlock , final IElementType parentStatement ) {
173
- PsiElement twigCompositeElement = PsiTreeUtil .findFirstParent (psiInsideBlock , psiElement -> {
174
- if (psiElement instanceof TwigCompositeElement ) {
175
- if (PlatformPatterns .psiElement (parentStatement ).accepts (psiElement )) {
176
- return true ;
177
- }
178
- }
179
- return false ;
180
- });
172
+ private static Map <String , String > findInlineStatementVariableDocBlock (@ NotNull PsiElement psiInsideBlock , @ NotNull IElementType parentStatement , boolean nextParent ) {
173
+ PsiElement twigCompositeElement = PsiTreeUtil .findFirstParent (psiInsideBlock , psiElement ->
174
+ PlatformPatterns .psiElement (parentStatement ).accepts (psiElement )
175
+ );
181
176
182
177
Map <String , String > variables = new HashMap <>();
183
178
if (twigCompositeElement == null ) {
184
179
return variables ;
185
180
}
186
181
187
- return getInlineCommentDocsVars (twigCompositeElement );
182
+ Map <String , String > inlineCommentDocsVars = getInlineCommentDocsVars (twigCompositeElement );
183
+
184
+ // visit parent elements for extending scope
185
+ if (nextParent ) {
186
+ PsiElement parent = twigCompositeElement .getParent ();
187
+ if (parent != null ) {
188
+ inlineCommentDocsVars .putAll (findInlineStatementVariableDocBlock (twigCompositeElement .getParent (), parentStatement , true ));
189
+ }
190
+ }
191
+
192
+ return inlineCommentDocsVars ;
188
193
}
189
194
190
195
/**
@@ -237,7 +242,6 @@ public static Map<String, PsiVariable> collectScopeVariables(@NotNull PsiElement
237
242
238
243
@ NotNull
239
244
public static Map <String , PsiVariable > collectScopeVariables (@ NotNull PsiElement psiElement , @ NotNull Set <VirtualFile > visitedFiles ) {
240
-
241
245
Map <String , Set <String >> globalVars = new HashMap <>();
242
246
Map <String , PsiVariable > controllerVars = new HashMap <>();
243
247
@@ -255,9 +259,9 @@ public static Map<String, PsiVariable> collectScopeVariables(@NotNull PsiElement
255
259
}
256
260
257
261
// globals first
258
- globalVars .putAll (convertHashMapToTypeSet (findInlineStatementVariableDocBlock (psiElement , TwigElementTypes .BLOCK_STATEMENT )));
259
- globalVars .putAll (convertHashMapToTypeSet (findInlineStatementVariableDocBlock (psiElement , TwigElementTypes .MACRO_STATEMENT )));
260
- globalVars .putAll (convertHashMapToTypeSet (findInlineStatementVariableDocBlock (psiElement , TwigElementTypes .FOR_STATEMENT )));
262
+ globalVars .putAll (convertHashMapToTypeSet (findInlineStatementVariableDocBlock (psiElement , TwigElementTypes .BLOCK_STATEMENT , true )));
263
+ globalVars .putAll (convertHashMapToTypeSet (findInlineStatementVariableDocBlock (psiElement , TwigElementTypes .MACRO_STATEMENT , false )));
264
+ globalVars .putAll (convertHashMapToTypeSet (findInlineStatementVariableDocBlock (psiElement , TwigElementTypes .FOR_STATEMENT , false )));
261
265
262
266
for (Map .Entry <String , Set <String >> entry : globalVars .entrySet ()) {
263
267
Set <String > types = entry .getValue ();
0 commit comments