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;
});
}
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()]);
}
Aggregations