Search in sources :

Example 1 with TemplateToolkitNamedBlock

use of com.perl5.lang.tt2.psi.TemplateToolkitNamedBlock 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)

Example 2 with TemplateToolkitNamedBlock

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

the class TemplateToolkitBlockReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PsiElement element = getElement();
    if (element == null) {
        return ResolveResult.EMPTY_ARRAY;
    }
    TextRange range = ElementManipulators.getValueTextRange(element);
    if (range == null) {
        return ResolveResult.EMPTY_ARRAY;
    }
    final CharSequence targetName = range.subSequence(element.getText());
    if (StringUtil.isEmpty(targetName)) {
        return ResolveResult.EMPTY_ARRAY;
    }
    final List<ResolveResult> result = new ArrayList<>();
    PsiTreeUtil.processElements(element.getContainingFile(), element1 -> {
        if (element1 instanceof TemplateToolkitNamedBlock && StringUtil.equals(((TemplateToolkitNamedBlock) element1).getName(), targetName)) {
            result.add(new PsiElementResolveResult(element1));
        }
        return true;
    });
    return result.toArray(new ResolveResult[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) TemplateToolkitNamedBlock(com.perl5.lang.tt2.psi.TemplateToolkitNamedBlock) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 TemplateToolkitNamedBlock (com.perl5.lang.tt2.psi.TemplateToolkitNamedBlock)2 TextRange (com.intellij.openapi.util.TextRange)1 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 ResolveResult (com.intellij.psi.ResolveResult)1 TemplateToolkitString (com.perl5.lang.tt2.psi.TemplateToolkitString)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1