Search in sources :

Example 1 with PodLinkToFileReference

use of com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference in project Perl5-IDEA by Camelcade.

the class PodLinkCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getOriginalPosition();
    if (element == null) {
        return;
    }
    PsiPodFormatLink psiPodFormatLink = PsiTreeUtil.getParentOfType(element, PsiPodFormatLink.class);
    if (psiPodFormatLink == null) {
        return;
    }
    TextRange elementRange = element.getTextRange().shiftRight(-psiPodFormatLink.getTextOffset());
    PsiReference[] references = psiPodFormatLink.getReferences();
    for (PsiReference reference : references) {
        TextRange referenceRange = reference.getRangeInElement();
        if (referenceRange.contains(elementRange)) {
            if (reference instanceof PodLinkToFileReference) {
                addFilesCompletions(psiPodFormatLink, result);
                return;
            } else if (reference instanceof PodLinkToSectionReference) {
                addSectionsCompletions(result, psiPodFormatLink.getTargetFile());
                return;
            }
        }
    }
    // checking for an empty section
    if (atSectionPosition(element)) {
        addSectionsCompletions(result, psiPodFormatLink.getTargetFile());
    }
}
Also used : PodLinkToFileReference(com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference) PsiPodFormatLink(com.perl5.lang.pod.psi.PsiPodFormatLink) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) PodLinkToSectionReference(com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PodLinkToFileReference

use of com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference in project Perl5-IDEA by Camelcade.

the class PodFormatterLMixin method computeReferences.

@Override
public PsiReference[] computeReferences() {
    List<PsiReference> references = new ArrayList<>();
    final PodLinkDescriptor descriptor = getLinkDescriptor();
    if (descriptor != null && !descriptor.isUrl()) {
        PsiElement contentBlock = getContentBlock();
        if (contentBlock != null) {
            int rangeOffset = contentBlock.getStartOffsetInParent();
            // file reference
            TextRange fileRange = descriptor.getFileIdTextRangeInLink();
            if (fileRange != null && !fileRange.isEmpty()) {
                references.add(new PodLinkToFileReference(this, fileRange.shiftRight(rangeOffset)));
            }
            // section reference
            TextRange sectionRange = descriptor.getSectionTextRangeInLink();
            if (sectionRange != null && !sectionRange.isEmpty()) {
                references.add(new PodLinkToSectionReference(this, sectionRange.shiftRight(rangeOffset)));
            }
        }
    }
    references.addAll(Arrays.asList(ReferenceProvidersRegistry.getReferencesFromProviders(this)));
    return references.toArray(new PsiReference[references.size()]);
}
Also used : PodLinkToFileReference(com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) PodLinkDescriptor(com.perl5.lang.pod.parser.psi.PodLinkDescriptor) PodLinkToSectionReference(com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PodLinkToFileReference

use of com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference in project Perl5-IDEA by Camelcade.

the class PodUnresolvableLinkInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PodVisitor() {

        @Override
        public void visitPodFormatLink(@NotNull PsiPodFormatLink o) {
            for (PsiReference reference : o.getReferences()) {
                if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length == 0) {
                    String error;
                    if (reference instanceof PodLinkToFileReference) {
                        String fileName = "UNKNONW";
                        PodLinkDescriptor descriptor = o.getLinkDescriptor();
                        if (descriptor != null && descriptor.getFileId() != null) {
                            fileName = descriptor.getFileId();
                        }
                        error = "Can't find POD or PM file by: " + fileName;
                    } else if (reference instanceof PodLinkToSectionReference) {
                        String fileName = "UNKNONW";
                        PodLinkDescriptor descriptor = o.getLinkDescriptor();
                        if (descriptor != null && descriptor.getSection() != null) {
                            fileName = descriptor.getSection();
                        }
                        error = "Can't find POD section: " + fileName;
                    } else {
                        error = "Can't find reference target";
                    }
                    holder.registerProblem(reference, error, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                }
            }
            super.visitPodFormatLink(o);
        }
    };
}
Also used : PodLinkToFileReference(com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference) PodVisitor(com.perl5.lang.pod.parser.psi.PodVisitor) PsiPodFormatLink(com.perl5.lang.pod.psi.PsiPodFormatLink) PsiReference(com.intellij.psi.PsiReference) PodLinkDescriptor(com.perl5.lang.pod.parser.psi.PodLinkDescriptor) NotNull(org.jetbrains.annotations.NotNull) PodLinkToSectionReference(com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiReference (com.intellij.psi.PsiReference)3 PodLinkToFileReference (com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference)3 PodLinkToSectionReference (com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference)3 TextRange (com.intellij.openapi.util.TextRange)2 PsiElement (com.intellij.psi.PsiElement)2 PodLinkDescriptor (com.perl5.lang.pod.parser.psi.PodLinkDescriptor)2 PsiPodFormatLink (com.perl5.lang.pod.psi.PsiPodFormatLink)2 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)1 PodVisitor (com.perl5.lang.pod.parser.psi.PodVisitor)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1