package fr.adrienbrault.idea.symfony2plugin.util.completion;

import com.intellij.codeInsight.completion.InsertHandler;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.lookup.LookupElement;
import com.jetbrains.php.completion.insert.PhpInsertHandlerUtil;
import org.jetbrains.annotations.NotNull;

public class FunctionInsertHandler implements InsertHandler<LookupElement> {

    private static final FunctionInsertHandler instance = new FunctionInsertHandler();

    public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {


        String addText = "()";
        PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText);

        context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true);

    }

    public static FunctionInsertHandler getInstance(){
        return instance;
    }

}

@@ -607,16 +607,208 @@
 ent) %7B%0A%0A
+        // check this:%0A        // %7B%7B form_javasc%7C() %7D%7D%0A        // %7B%7B form_javasc%7C %7D%7D%0A        if(PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), %22(%22)) %7B%0A            return;%0A        %7D%0A
 %0A       

fix twig function completion insert handler is fired on "test|()"