use of com.perl5.lang.pod.parser.psi.references.PodSubReference in project Perl5-IDEA by Camelcade.
the class PodIdentifierImpl method computeReferences.
@Override
public PsiReference[] computeReferences() {
final PodIdentifierImpl element = PodIdentifierImpl.this;
List<PsiReference> references = new ArrayList<>();
if (element.getParent() instanceof PodSectionTitle && element.getPrevSibling() == null) {
references.add(new PodSubReference(element));
}
references.addAll(Arrays.asList(ReferenceProvidersRegistry.getReferencesFromProviders(element)));
return references.toArray(new PsiReference[references.size()]);
}
use of com.perl5.lang.pod.parser.psi.references.PodSubReference in project Perl5-IDEA by Camelcade.
the class PodTitleCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
PsiElement elementParent = element.getParent();
if (PsiUtilCore.getElementType(element) != POD_IDENTIFIER || element.getPrevSibling() != null || !(elementParent instanceof PodSectionTitle)) {
return;
}
IElementType grandparentElementType = PsiUtilCore.getElementType(elementParent.getParent());
PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, element);
if (grandparentElementType == HEAD_1_SECTION) {
for (String sectionTitle : DEFAULT_POD_SECTIONS) {
if (completionProcessor.matches(sectionTitle) && !completionProcessor.process(LookupElementBuilder.create(sectionTitle))) {
break;
}
}
}
final PsiFile elementFile = element.getContainingFile().getOriginalFile();
final PsiFile perlFile = PodFileUtil.getTargetPerlFile(elementFile);
if (perlFile == null) {
return;
}
Set<PerlSubElement> possibleTargets = new HashSet<>();
PerlPsiUtil.processSubElements(perlFile, possibleTargets::add);
elementFile.accept(new PodRecursiveVisitor() {
@Override
public void visitTargetableSection(PodTitledSection o) {
processSection(o);
super.visitTargetableSection(o);
}
private void processSection(@NotNull PodTitledSection o) {
PsiElement titleBlock = o.getTitleElement();
if (titleBlock == null) {
return;
}
PsiElement firstChild = titleBlock.getFirstChild();
if (firstChild == null) {
return;
}
// noinspection SuspiciousMethodCalls
Arrays.stream(firstChild.getReferences()).filter(it -> it instanceof PodSubReference).flatMap(it -> Arrays.stream(((PodSubReference) it).multiResolve(false))).map(ResolveResult::getElement).forEach(possibleTargets::remove);
}
});
for (PerlSubElement subElement : possibleTargets) {
String lookupString = StringUtil.notNullize(subElement.getPresentableName());
if (completionProcessor.matches(lookupString) && !completionProcessor.process(LookupElementBuilder.create(subElement, lookupString).withIcon(subElement.getIcon(0)))) {
break;
}
}
completionProcessor.logStatus(getClass());
}
Aggregations