@@ -225,6 +225,38 @@ public static ElementPattern<PsiElement> getPrintBlockOrTagFunctionPattern() {
225225 .withLanguage (TwigLanguage .INSTANCE );
226226 }
227227
228+ /**
229+ * Check for {{ foo(bar, '|') }}, {% foo(bar, '|') %}
230+ *
231+ * @param functionName twig function name
232+ */
233+ public static ElementPattern <PsiElement > getPrintBlockOrTagFunctionSecondParameterPattern (String ... functionName ) {
234+ return PlatformPatterns
235+ .psiElement (TwigTokenTypes .STRING_TEXT )
236+ .withParent (
237+ getFunctionCallScopePattern ()
238+ )
239+ .afterLeafSkipping (
240+ PlatformPatterns .or (
241+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
242+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
243+ PlatformPatterns .psiElement (TwigTokenTypes .SINGLE_QUOTE ),
244+ PlatformPatterns .psiElement (TwigTokenTypes .DOUBLE_QUOTE )
245+ ),
246+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA ).afterLeafSkipping (
247+ PlatformPatterns .or (PARAMETER_WHITE_LIST ),
248+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE ).afterLeafSkipping (
249+ PlatformPatterns .or (
250+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
251+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE )
252+ ),
253+ PlatformPatterns .psiElement (TwigTokenTypes .IDENTIFIER ).withText (PlatformPatterns .string ().oneOf (functionName ))
254+ )
255+ )
256+ )
257+ .withLanguage (TwigLanguage .INSTANCE );
258+ }
259+
228260 /**
229261 * {{ foo('<caret>') }}
230262 * {{ 'test'|foo('<caret>') }}
@@ -279,6 +311,47 @@ public static ElementPattern<PsiElement> getFunctionWithFirstParameterAsLiteralP
279311 .withLanguage (TwigLanguage .INSTANCE );
280312 }
281313
314+ /**
315+ * Literal as second parameter
316+ *
317+ * {{ foo(bar, {'foobar', 'foo<caret>bar'}) }}
318+ * {{ foo(bar, {'fo<caret>obar'}) }}
319+ */
320+ public static ElementPattern <PsiElement > getFunctionWithSecondParameterAsLiteralPattern (@ NotNull String ... functionName ) {
321+ return PlatformPatterns
322+ .psiElement (TwigTokenTypes .STRING_TEXT ).afterLeafSkipping (
323+ PlatformPatterns .or (
324+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
325+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
326+ PlatformPatterns .psiElement (TwigTokenTypes .SINGLE_QUOTE ),
327+ PlatformPatterns .psiElement (TwigTokenTypes .DOUBLE_QUOTE )
328+ ),
329+ PlatformPatterns .or (
330+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE_CURL ),
331+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA )
332+ )
333+ )
334+ .withParent (
335+ PlatformPatterns .psiElement (TwigElementTypes .LITERAL ).afterLeafSkipping (
336+ PlatformPatterns .or (
337+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
338+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE )
339+ ),
340+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA ).afterLeafSkipping (
341+ PlatformPatterns .or (PARAMETER_WHITE_LIST ),
342+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE ).afterLeafSkipping (
343+ PlatformPatterns .or (
344+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
345+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE )
346+ ),
347+ PlatformPatterns .psiElement (TwigTokenTypes .IDENTIFIER ).withText (PlatformPatterns .string ().oneOf (functionName ))
348+ )
349+ )
350+ )
351+ )
352+ .withLanguage (TwigLanguage .INSTANCE );
353+ }
354+
282355 /**
283356 * {{ foo({'foo<caret>bar': 'foo'}}) }}
284357 * {{ foo({'foobar': 'foo', 'foo<caret>bar': 'foo'}}) }}
@@ -431,6 +504,74 @@ public static ElementPattern<PsiElement> getFunctionWithFirstParameterAsArrayPat
431504 );
432505 }
433506
507+ /**
508+ * Array values as second parameter
509+ *
510+ * {{ foo(bar, ['foobar', 'foo<caret>bar']) }}
511+ * {{ foo(bar, ['fo<caret>obar']) }}
512+ */
513+ public static ElementPattern <PsiElement > getFunctionWithSecondParameterAsArrayPattern (@ NotNull String ... functionName ) {
514+
515+ // "foo(param, [<caret>"
516+ PsiElementPattern .Capture <PsiElement > functionPattern = PlatformPatterns
517+ .psiElement (TwigTokenTypes .LBRACE_SQ )
518+ .afterLeafSkipping (
519+ PlatformPatterns .or (
520+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
521+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE )
522+ ),
523+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA ).afterLeafSkipping (
524+ PlatformPatterns .or (PARAMETER_WHITE_LIST ),
525+ PlatformPatterns .psiElement (TwigTokenTypes .LBRACE ).afterLeafSkipping (
526+ PlatformPatterns .or (
527+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
528+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE )
529+ ),
530+ PlatformPatterns .psiElement (TwigTokenTypes .IDENTIFIER ).withText (PlatformPatterns .string ().oneOf (functionName ))
531+ )
532+ )
533+ );
534+
535+ return
536+ PlatformPatterns .or (
537+ // {{ foo(bar, ['fo<caret>obar']) }}
538+ PlatformPatterns
539+ .psiElement (TwigTokenTypes .STRING_TEXT ).afterLeafSkipping (
540+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
541+ PlatformPatterns .psiElement ().withElementType (PlatformPatterns .elementType ().or (
542+ TwigTokenTypes .SINGLE_QUOTE ,
543+ TwigTokenTypes .DOUBLE_QUOTE
544+ )).afterLeafSkipping (
545+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
546+ functionPattern
547+ )
548+ ).withLanguage (TwigLanguage .INSTANCE ),
549+
550+ // {{ foo(bar, ['foobar', 'foo<caret>bar']) }}
551+ PlatformPatterns
552+ .psiElement (TwigTokenTypes .STRING_TEXT ).afterLeafSkipping (
553+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
554+ PlatformPatterns .psiElement ().withElementType (PlatformPatterns .elementType ().or (
555+ TwigTokenTypes .SINGLE_QUOTE ,
556+ TwigTokenTypes .DOUBLE_QUOTE
557+ )).afterLeafSkipping (
558+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
559+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA ).afterLeafSkipping (
560+ PlatformPatterns .or (
561+ PlatformPatterns .psiElement (TwigTokenTypes .WHITE_SPACE ),
562+ PlatformPatterns .psiElement (PsiWhiteSpace .class ),
563+ PlatformPatterns .psiElement (TwigTokenTypes .STRING_TEXT ),
564+ PlatformPatterns .psiElement (TwigTokenTypes .SINGLE_QUOTE ),
565+ PlatformPatterns .psiElement (TwigTokenTypes .DOUBLE_QUOTE ),
566+ PlatformPatterns .psiElement (TwigTokenTypes .COMMA )
567+ ),
568+ functionPattern
569+ )
570+ )
571+ ).withLanguage (TwigLanguage .INSTANCE )
572+ );
573+ }
574+
434575 /**
435576 * {% render "foo"
436577 *
0 commit comments