@@ -233,14 +233,17 @@ public static Map<String, Collection<PsiElement>> getTemplateAnnotationFilesWith
233
233
public static String getTransDefaultDomainOnScope (@ NotNull PsiElement position ) {
234
234
// {% embed 'foo.html.twig' with { foo: '<caret>'|trans } %}
235
235
PsiElement parent = position .getParent ();
236
- if (parent != null && parent .getNode ().getElementType () == TwigElementTypes .EMBED_TAG ) {
237
- PsiElement firstParent = PsiTreeUtil .findFirstParent (position , true , psiElement -> {
238
- IElementType elementType = psiElement .getNode ().getElementType ();
239
- return elementType != TwigElementTypes .EMBED_TAG && elementType != TwigElementTypes .EMBED_STATEMENT ;
240
- });
236
+ if (parent != null && parent .getNode ().getElementType () == TwigElementTypes .LITERAL ) {
237
+ PsiElement parent2 = parent .getParent ();
238
+ if (parent2 != null && parent2 .getNode ().getElementType () == TwigElementTypes .EMBED_TAG ) {
239
+ PsiElement firstParent = PsiTreeUtil .findFirstParent (parent , true , psiElement -> {
240
+ IElementType elementType = psiElement .getNode ().getElementType ();
241
+ return elementType != TwigElementTypes .EMBED_TAG && elementType != TwigElementTypes .EMBED_STATEMENT ;
242
+ });
241
243
242
- if (firstParent != null ) {
243
- position = firstParent ;
244
+ if (firstParent != null ) {
245
+ position = firstParent ;
246
+ }
244
247
}
245
248
}
246
249
@@ -1555,23 +1558,27 @@ public static Collection<String> getIncludeTagStrings(@NotNull TwigTagWithFileRe
1555
1558
1556
1559
/**
1557
1560
* Visit string values of given array start brace
1558
- * ["foobar"]
1561
+ *
1562
+ * ["foobar", "foobar"]
1563
+ * {"foobar", "foobar"}
1559
1564
*/
1560
- public static void visitStringInArray (@ NotNull PsiElement arrayStartBrace , @ NotNull Consumer <Pair <String , PsiElement >> pair ) {
1565
+ private static void visitStringInArray (@ NotNull PsiElement arrayStartBrace , @ NotNull Consumer <Pair <String , PsiElement >> pair ) {
1561
1566
// match: "([,)''(,])"
1562
1567
Collection <PsiElement > questString = PsiElementUtils .getNextSiblingOfTypes (arrayStartBrace , PlatformPatterns .psiElement (TwigTokenTypes .STRING_TEXT )
1563
1568
.afterLeafSkipping (
1564
1569
TwigPattern .STRING_WRAP_PATTERN ,
1565
1570
PlatformPatterns .or (
1566
1571
PlatformPatterns .psiElement (TwigTokenTypes .COMMA ),
1567
- PlatformPatterns .psiElement (TwigTokenTypes .LBRACE_SQ )
1568
- )
1572
+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE_SQ ),
1573
+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE_CURL )
1574
+ )
1569
1575
)
1570
1576
.beforeLeafSkipping (
1571
1577
TwigPattern .STRING_WRAP_PATTERN ,
1572
1578
PlatformPatterns .or (
1573
1579
PlatformPatterns .psiElement (TwigTokenTypes .COMMA ),
1574
- PlatformPatterns .psiElement (TwigTokenTypes .RBRACE_SQ )
1580
+ PlatformPatterns .psiElement (TwigTokenTypes .RBRACE_SQ ),
1581
+ PlatformPatterns .psiElement (TwigTokenTypes .RBRACE_CURL )
1575
1582
)
1576
1583
)
1577
1584
);
@@ -1619,7 +1626,7 @@ public void visitElement(PsiElement element) {
1619
1626
psiElement .acceptChildren (new PsiRecursiveElementVisitor () {
1620
1627
@ Override
1621
1628
public void visitElement (PsiElement element ) {
1622
- if (target [0 ] == null && TwigPattern .getPrintBlockFunctionPattern ("block" ).accepts (element )) {
1629
+ if (target [0 ] == null && TwigPattern .getPrintBlockOrTagFunctionPattern ("block" ).accepts (element )) {
1623
1630
target [0 ] = element ;
1624
1631
}
1625
1632
super .visitElement (element );
@@ -2212,7 +2219,12 @@ public static void visitTemplateIncludes(@NotNull TwigFile twigFile, @NotNull Co
2212
2219
visitTemplateIncludes (
2213
2220
twigFile ,
2214
2221
consumer ,
2215
- TemplateInclude .TYPE .EMBED , TemplateInclude .TYPE .INCLUDE , TemplateInclude .TYPE .INCLUDE_FUNCTION , TemplateInclude .TYPE .FROM , TemplateInclude .TYPE .IMPORT , TemplateInclude .TYPE .FORM_THEME
2222
+ TemplateInclude .TYPE .EMBED ,
2223
+ TemplateInclude .TYPE .INCLUDE ,
2224
+ TemplateInclude .TYPE .INCLUDE_FUNCTION ,
2225
+ TemplateInclude .TYPE .FROM ,
2226
+ TemplateInclude .TYPE .IMPORT ,
2227
+ TemplateInclude .TYPE .FORM_THEME
2216
2228
);
2217
2229
}
2218
2230
@@ -2261,7 +2273,7 @@ private static void visitTemplateIncludes(@NotNull TwigFile twigFile, @NotNull C
2261
2273
// {{ include() }}
2262
2274
// {{ source() }}
2263
2275
if (myTypes .contains (TemplateInclude .TYPE .INCLUDE_FUNCTION )) {
2264
- PsiElement includeTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getPrintBlockFunctionPattern ("include" , "source" ));
2276
+ PsiElement includeTag = PsiElementUtils .getChildrenOfType (psiElement , TwigPattern .getPrintBlockOrTagFunctionPattern ("include" , "source" ));
2265
2277
if (includeTag != null ) {
2266
2278
String templateName = includeTag .getText ();
2267
2279
if (StringUtils .isNotBlank (templateName )) {
@@ -2298,17 +2310,21 @@ private static void visitTemplateIncludes(@NotNull TwigFile twigFile, @NotNull C
2298
2310
}
2299
2311
}
2300
2312
2301
- // {% form_theme form.child 'form/fields_child.html.twig' %}
2313
+ // {% form_theme form.child with [ 'form/fields_child.html.twig'] %}
2302
2314
PsiElement withElement = PsiElementUtils .getNextSiblingOfType (tagElement , PlatformPatterns .psiElement ().withElementType (TwigTokenTypes .IDENTIFIER ).withText ("with" ));
2303
2315
if (withElement != null ) {
2304
- PsiElement arrayStart = PsiElementUtils .getNextSiblingAndSkip (tagElement , TwigTokenTypes .LBRACE_SQ ,
2316
+ // find LITERAL "[", "{"
2317
+ PsiElement arrayStart = PsiElementUtils .getNextSiblingAndSkip (tagElement , TwigElementTypes .LITERAL ,
2305
2318
TwigTokenTypes .IDENTIFIER , TwigTokenTypes .SINGLE_QUOTE , TwigTokenTypes .DOUBLE_QUOTE , TwigTokenTypes .DOT
2306
2319
);
2307
2320
2308
2321
if (arrayStart != null ) {
2309
- visitStringInArray (arrayStart , pair ->
2310
- consumer .consume (new TemplateInclude (psiElement , pair .getFirst (), TemplateInclude .TYPE .FORM_THEME ))
2311
- );
2322
+ PsiElement firstChild = arrayStart .getFirstChild ();
2323
+ if (firstChild != null ) {
2324
+ visitStringInArray (firstChild , pair ->
2325
+ consumer .consume (new TemplateInclude (psiElement , pair .getFirst (), TemplateInclude .TYPE .FORM_THEME ))
2326
+ );
2327
+ }
2312
2328
}
2313
2329
}
2314
2330
}
0 commit comments