Search in sources :

Example 6 with PodFormatterL

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

the class PodLinkCompletionProvider method processFilesCompletions.

protected boolean processFilesCompletions(@NotNull PerlCompletionProcessor completionProcessor) {
    PodFormatterL linkElement = (PodFormatterL) completionProcessor.getLeafElement();
    final Set<String> foundPods = new HashSet<>();
    PerlPackageUtil.processIncFilesForPsiElement(linkElement, (file, classRoot) -> {
        String className = PodFileUtil.getPackageNameFromVirtualFile(file, classRoot);
        if (StringUtil.isNotEmpty(className)) {
            boolean isBuiltIn = false;
            if (StringUtil.startsWith(className, "pod::")) {
                isBuiltIn = true;
                className = className.substring(5);
            }
            if (completionProcessor.matches(className) && foundPods.add(className)) {
                if (!completionProcessor.process(LookupElementBuilder.create(file, className).withIcon(PerlIcons.POD_FILE).withBoldness(isBuiltIn))) {
                    return false;
                }
            }
        }
        return completionProcessor.result();
    }, PodFileType.INSTANCE);
    return PerlPackageUtil.processPackageFilesForPsiElement(linkElement, (packageName, file) -> {
        if (StringUtil.isNotEmpty(packageName) && completionProcessor.matches(packageName) && foundPods.add(packageName)) {
            return PerlPackageCompletionUtil.processPackageLookupElement(file, packageName, null, completionProcessor, false);
        }
        return completionProcessor.result();
    });
}
Also used : PodFormatterL(com.perl5.lang.pod.parser.psi.mixin.PodFormatterL)

Example 7 with PodFormatterL

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

the class PodLinkDescriptor method create.

@Nullable
public static PodLinkDescriptor create(@NotNull PodFormatterL formatterL) {
    PsiLinkText textElement = formatterL.getLinkTextElement();
    PsiLinkName nameElement = formatterL.getLinkNameElement();
    PsiLinkSection sectionElement = formatterL.getLinkSectionElement();
    PsiLinkUrl linkUrlElement = formatterL.getLinkUrlElement();
    if (nameElement == null && sectionElement == null && linkUrlElement == null) {
        return null;
    }
    String linkTextText = null;
    String linkTextHtml = null;
    String linkName = null;
    String linkSection = null;
    boolean isUrl = false;
    boolean isSameFile = false;
    if (textElement != null) {
        linkTextHtml = PodRenderUtil.renderPsiElementAsHTML(textElement);
        linkTextText = PodRenderUtil.renderPsiElementAsText(textElement);
    }
    if (linkUrlElement != null) {
        isUrl = true;
        linkName = linkUrlElement.getText();
        if (linkTextText == null) {
            linkTextText = linkTextHtml = linkName;
        }
    } else if (sectionElement != null) {
        linkSection = PodRenderUtil.renderPsiElementAsText(sectionElement);
        if (linkTextText == null) {
            linkTextHtml = PodRenderUtil.renderPsiElementAsHTML(sectionElement);
            linkTextText = linkSection;
            if (nameElement != null) {
                linkName = nameElement.getText();
                linkTextHtml = buildTitle(linkName, linkTextHtml, false);
                linkTextText = buildTitle(linkName, linkTextText, false);
            }
        }
    }
    if (linkName == null) {
        if (nameElement != null) {
            linkName = nameElement.getText();
        } else {
            PsiFile containingFile = formatterL.getContainingFile();
            if (containingFile instanceof PodLinkTarget) {
                linkName = ((PodLinkTarget) containingFile).getPodLink();
                isSameFile = true;
            }
        }
    }
    return new PodLinkDescriptor(linkName, linkSection, linkTextText, linkTextHtml, isUrl, isSameFile);
}
Also used : PsiLinkText(com.perl5.lang.pod.psi.PsiLinkText) PsiLinkName(com.perl5.lang.pod.psi.PsiLinkName) PsiFile(com.intellij.psi.PsiFile) PsiLinkSection(com.perl5.lang.pod.psi.PsiLinkSection) PsiLinkUrl(com.perl5.lang.pod.psi.PsiLinkUrl) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PodFormatterL (com.perl5.lang.pod.parser.psi.mixin.PodFormatterL)6 NotNull (org.jetbrains.annotations.NotNull)4 PodLinkDescriptor (com.perl5.lang.pod.parser.psi.PodLinkDescriptor)3 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 IElementType (com.intellij.psi.tree.IElementType)2 PodVisitor (com.perl5.lang.pod.parser.psi.PodVisitor)2 PsiLinkSection (com.perl5.lang.pod.psi.PsiLinkSection)2 PsiPodFormatLink (com.perl5.lang.pod.psi.PsiPodFormatLink)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)1 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)1 PsiReference (com.intellij.psi.PsiReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 PerlSimpleCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)1 PodStubsAwareRecursiveVisitor (com.perl5.lang.pod.parser.psi.PodStubsAwareRecursiveVisitor)1 PodTitledSection (com.perl5.lang.pod.parser.psi.PodTitledSection)1 PodLinkToFileReference (com.perl5.lang.pod.parser.psi.references.PodLinkToFileReference)1 PodLinkToSectionReference (com.perl5.lang.pod.parser.psi.references.PodLinkToSectionReference)1 PsiLinkName (com.perl5.lang.pod.psi.PsiLinkName)1