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