Search in sources :

Example 1 with PsiLinkText

use of com.perl5.lang.pod.psi.PsiLinkText in project Perl5-IDEA by Camelcade.

the class PodTypedHandler method shouldShowPopup.

@Override
protected boolean shouldShowPopup(char typedChar, @NotNull Project project, @NotNull Editor editor, @Nullable PsiElement element) {
    IElementType elementType = PsiUtilCore.getElementType(element);
    ASTNode elementNode = ObjectUtils.doIfNotNull(element, PsiElement::getNode);
    CharSequence elementChars = ObjectUtils.doIfNotNull(elementNode, ASTNode::getChars);
    PsiElement elementParent = ObjectUtils.doIfNotNull(element, PsiElement::getParent);
    IElementType parentType = PsiUtilCore.getElementType(elementParent);
    return typedChar == '=' && isCommandPosition(editor, elementType, elementChars) || typedChar == ':' && elementNode != null && PerlEditorUtil.isPreviousToken(editor, elementNode.getStartOffset(), FORMAT_ACCEPTING_COMMANDS) || typedChar == ' ' && PodTokenSets.POD_COMMANDS_TOKENSET.contains(elementType) || typedChar == '<' && elementType == POD_IDENTIFIER && StringUtil.equals("L", elementChars) || typedChar == '|' && parentType == LINK_NAME || typedChar == '/' && (parentType == LINK_NAME || elementType == POD_ANGLE_LEFT && parentType == POD_FORMAT_LINK || elementType == POD_PIPE && element.getPrevSibling() instanceof PsiLinkText) || isInsideSection(element);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiLinkText(com.perl5.lang.pod.psi.PsiLinkText) ASTNode(com.intellij.lang.ASTNode) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 2 with PsiLinkText

use of com.perl5.lang.pod.psi.PsiLinkText 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

PsiLinkText (com.perl5.lang.pod.psi.PsiLinkText)2 ASTNode (com.intellij.lang.ASTNode)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 IElementType (com.intellij.psi.tree.IElementType)1 PsiLinkName (com.perl5.lang.pod.psi.PsiLinkName)1 PsiLinkSection (com.perl5.lang.pod.psi.PsiLinkSection)1 PsiLinkUrl (com.perl5.lang.pod.psi.PsiLinkUrl)1 Nullable (org.jetbrains.annotations.Nullable)1