Search in sources :

Example 1 with TemplateToolkitString

use of com.perl5.lang.tt2.psi.TemplateToolkitString in project Perl5-IDEA by Camelcade.

the class TemplateToolkitBlocksCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet result) {
    PsiElement element = parameters.getOriginalPosition();
    if (element == null) {
        return;
    }
    PsiElement stringElement = element.getParent();
    if (!(stringElement instanceof TemplateToolkitString)) {
        return;
    }
    PsiElement container = stringElement.getParent();
    if (!TemplateToolkitStringMixin.BLOCK_NAME_TARGETED_CONTAINERS.contains(PsiUtilCore.getElementType(container))) {
        return;
    }
    PsiTreeUtil.processElements(element.getContainingFile(), element1 -> {
        if (element1 instanceof TemplateToolkitNamedBlock) {
            String blockName = ((TemplateToolkitNamedBlock) element1).getName();
            if (StringUtil.isNotEmpty(blockName)) {
                result.addElement(LookupElementBuilder.create(blockName).withTypeText("BLOCK", true).withIcon(element1.getIcon(0)));
            }
        }
        return true;
    });
}
Also used : TemplateToolkitString(com.perl5.lang.tt2.psi.TemplateToolkitString) TemplateToolkitNamedBlock(com.perl5.lang.tt2.psi.TemplateToolkitNamedBlock) TemplateToolkitString(com.perl5.lang.tt2.psi.TemplateToolkitString) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 TemplateToolkitNamedBlock (com.perl5.lang.tt2.psi.TemplateToolkitNamedBlock)1 TemplateToolkitString (com.perl5.lang.tt2.psi.TemplateToolkitString)1