File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
main/java/fr/adrienbrault/idea/symfony2plugin/templating
test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -558,11 +558,15 @@ static ElementPattern<PsiElement> getPrintBlockFunctionPattern() {
558558 return PlatformPatterns .psiElement (TwigTokenTypes .IDENTIFIER ).withParent (getFunctionCallScopePattern ()).withLanguage (TwigLanguage .INSTANCE );
559559 }
560560
561- static ElementPattern <PsiElement > getFunctionPattern (@ NotNull String ...functionName ) {
561+ public static ElementPattern <PsiElement > getFunctionPattern (@ NotNull String ...functionName ) {
562562 return PlatformPatterns .psiElement (TwigElementTypes .FUNCTION_CALL ).withText (PlatformPatterns .string ().with (new PatternCondition <String >("Twig: Function call" ) {
563563 @ Override
564- public boolean accepts (@ NotNull String s , ProcessingContext processingContext ) {
565- return Arrays .asList (functionName ).contains (s );
564+ public boolean accepts (@ NotNull String function , ProcessingContext processingContext ) {
565+ String funcWithoutSpace = function .replaceAll (" +" , "" );
566+
567+ return Arrays .stream (functionName ).anyMatch (wantFunction ->
568+ funcWithoutSpace .startsWith (wantFunction + "(" ) || funcWithoutSpace .equals (wantFunction )
569+ );
566570 }
567571 }));
568572 }
Original file line number Diff line number Diff line change @@ -68,6 +68,23 @@ public void testGetPrintBlockOrTagFunctionPattern() {
6868 ));
6969 }
7070
71+ /**
72+ * @see fr.adrienbrault.idea.symfony2plugin.templating.TwigPattern#getFunctionPattern
73+ */
74+ public void testgetFunctionPattern () {
75+ assertTrue (fr .adrienbrault .idea .symfony2plugin .templating .TwigPattern .getFunctionPattern ("form" ).accepts (
76+ findElementAt (TwigFileType .INSTANCE , "{{ for<caret>m(test) }}" ).getParent ()
77+ ));
78+
79+ assertTrue (fr .adrienbrault .idea .symfony2plugin .templating .TwigPattern .getFunctionPattern ("form" ).accepts (
80+ findElementAt (TwigFileType .INSTANCE , "{{ for<caret>m (test) }}" ).getParent ()
81+ ));
82+
83+ assertFalse (fr .adrienbrault .idea .symfony2plugin .templating .TwigPattern .getFunctionPattern ("f" ).accepts (
84+ findElementAt (TwigFileType .INSTANCE , "{{ for<caret>m(test) }}" ).getParent ()
85+ ));
86+ }
87+
7188 /**
7289 * @see fr.adrienbrault.idea.symfony2plugin.templating.TwigPattern#getFunctionWithFirstParameterAsArrayPattern
7390 */
You can’t perform that action at this time.
0 commit comments