@@ -549,6 +549,7 @@ public static ElementPattern<PsiElement> getTagTernaryPattern(@NotNull IElementT
549
549
.withLanguage (TwigLanguage .INSTANCE )
550
550
);
551
551
}
552
+
552
553
/**
553
554
* Check for {{ include('|') }}, {% include('|') %}
554
555
*
@@ -581,6 +582,100 @@ public static ElementPattern<PsiElement> getPrintBlockOrTagFunctionPattern(Strin
581
582
.withLanguage (TwigLanguage .INSTANCE );
582
583
}
583
584
585
+ /**
586
+ * Literal are fine in lexer so just extract the parameter
587
+ *
588
+ * {{ foo({'foobar', 'foo<caret>bar'}) }}
589
+ * {{ foo({'fo<caret>obar'}) }}
590
+ */
591
+ public static ElementPattern <PsiElement > getFunctionWithFirstParameterAsLiteralPattern (@ NotNull String ... functionName ) {
592
+ //noinspection unchecked
593
+ return PlatformPatterns
594
+ .psiElement (TwigTokenTypes .STRING_TEXT ).afterLeafSkipping (
595
+ PlatformPatterns .or (
596
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
597
+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
598
+ PlatformPatterns .psiElement (TwigTokenTypes .SINGLE_QUOTE ),
599
+ PlatformPatterns .psiElement (TwigTokenTypes .DOUBLE_QUOTE )
600
+ ),
601
+ PlatformPatterns .or (
602
+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE_CURL ),
603
+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA )
604
+ )
605
+ )
606
+ .withParent (
607
+ PlatformPatterns .psiElement (TwigElementTypes .LITERAL ).afterLeafSkipping (
608
+ PlatformPatterns .or (
609
+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE ),
610
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
611
+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE )
612
+ ),
613
+ PlatformPatterns .psiElement (TwigTokenTypes .IDENTIFIER ).withText (PlatformPatterns .string ().oneOf (functionName ))
614
+ )
615
+ )
616
+ .withLanguage (TwigLanguage .INSTANCE );
617
+ }
618
+
619
+ /**
620
+ * Array values are not detected by lexer, lets do the magic on our own
621
+ *
622
+ * {{ foo(['foobar', 'foo<caret>bar']) }}
623
+ * {{ foo(['fo<caret>obar']) }}
624
+ */
625
+ public static ElementPattern <PsiElement > getFunctionWithFirstParameterAsArrayPattern (@ NotNull String ... functionName ) {
626
+ //noinspection unchecked
627
+
628
+ // "foo(<caret>"
629
+ PsiElementPattern .Capture <PsiElement > functionPattern = PlatformPatterns
630
+ .psiElement (TwigTokenTypes .LBRACE_SQ )
631
+ .afterLeafSkipping (
632
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
633
+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE ).afterLeafSkipping (
634
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
635
+ PlatformPatterns .psiElement (TwigTokenTypes .IDENTIFIER ).withText (PlatformPatterns .string ().oneOf (functionName ))
636
+ )
637
+ );
638
+
639
+ return
640
+ PlatformPatterns .or (
641
+ // {{ foo(['fo<caret>obar']) }}
642
+ PlatformPatterns
643
+ .psiElement (TwigTokenTypes .STRING_TEXT ).afterLeafSkipping (
644
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
645
+ PlatformPatterns .psiElement ().withElementType (PlatformPatterns .elementType ().or (
646
+ TwigTokenTypes .SINGLE_QUOTE ,
647
+ TwigTokenTypes .DOUBLE_QUOTE
648
+ )).afterLeafSkipping (
649
+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
650
+ functionPattern
651
+ )
652
+ ).withLanguage (TwigLanguage .INSTANCE ),
653
+
654
+ // {{ foo(['foobar', 'foo<caret>bar']) }}
655
+ PlatformPatterns
656
+ .psiElement (TwigTokenTypes .STRING_TEXT ).afterLeafSkipping (
657
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
658
+ PlatformPatterns .psiElement ().withElementType (PlatformPatterns .elementType ().or (
659
+ TwigTokenTypes .SINGLE_QUOTE ,
660
+ TwigTokenTypes .DOUBLE_QUOTE
661
+ )).afterLeafSkipping (
662
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
663
+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA ).afterLeafSkipping (
664
+ PlatformPatterns .or (
665
+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
666
+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
667
+ PlatformPatterns .psiElement (TwigTokenTypes .STRING_TEXT ),
668
+ PlatformPatterns .psiElement (TwigTokenTypes .SINGLE_QUOTE ),
669
+ PlatformPatterns .psiElement (TwigTokenTypes .DOUBLE_QUOTE ),
670
+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA )
671
+ ),
672
+ functionPattern
673
+ )
674
+ )
675
+ ).withLanguage (TwigLanguage .INSTANCE )
676
+ );
677
+ }
678
+
584
679
/**
585
680
* {% render "foo"
586
681
*
0 commit comments