Advanced Php element pattern
Hello,
I need some help with an ElementPattern for my CompletionContributor.
class GoodsDetailCore
{
public static function Get($fields, $class = '')
{
return
GetTemplate('goods/GoodsDetail',
[
'fields' => $fields,
'class' => $class
]);
}
public static function Head($fields, $class = '')
{
return
GetTemplate('start code completion inside the quotes',
[
'fields' => $fields,
'class' => $class
]);
}
How do I write the pattern for that? I've tried using the same thing as I used for ReferenceContributor, but it does not work. I used this (kotlin):
val templateMethodPattern = object : PsiNamePatternCondition<PsiElement>("withFunctionName", StandardPatterns.string().matches("GetTemplate")) {
override fun getPropertyValue(o: Any): String? {
return if (o is FunctionReference) o.name else null
}
}
val elementPattern = psiElement().withElementType(PhpElementTypes.STRING).
withParent(psiElement().withElementType(PhpElementTypes.PARAMETER_LIST).withParent(psiElement().
withElementType(PhpElementTypes.FUNCTION_CALL).with(templateMethodPattern)))
extend(CompletionType.BASIC, elementPattern, CompletionProvider())
I tried many things, but nothing worked.
Please sign in to leave a comment.
You need to provide completion inside a string, so instead of
you need
It still does not work, but I've made some progress:
Using elementPattern without the last parent (psiWithGetTemplateCall) does trigger completion properly, however, I need it only inside the GetTemplate function call, and that does not work yet. Using it without this part:
...does not work either. So what next?
In your pattern, you write that function call should be a parent of a string not a parent of a parameter list. It would be better to use:
or even:
Thank you, it works as it should!