Search in sources :

Example 1 with FoldingBuilder

use of com.intellij.lang.folding.FoldingBuilder in project intellij-community by JetBrains.

the class FoldingPolicy method isCollapseByDefault.

public static boolean isCollapseByDefault(PsiElement element) {
    final Language lang = element.getLanguage();
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
    try {
        return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode());
    } catch (IndexNotReadyException e) {
        LOG.error(e);
        return false;
    }
}
Also used : FoldingBuilder(com.intellij.lang.folding.FoldingBuilder) Language(com.intellij.lang.Language) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 2 with FoldingBuilder

use of com.intellij.lang.folding.FoldingBuilder in project intellij-community by JetBrains.

the class FoldingUpdate method getFoldingsFor.

private static void getFoldingsFor(@NotNull PsiFile file, @NotNull Document document, @NotNull FoldingMap elementsToFoldMap, boolean quick) {
    final FileViewProvider viewProvider = file.getViewProvider();
    TextRange docRange = TextRange.from(0, document.getTextLength());
    for (final Language language : viewProvider.getLanguages()) {
        final PsiFile psi = viewProvider.getPsi(language);
        final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
        if (psi != null && foldingBuilder != null) {
            for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) {
                PsiElement psiElement = descriptor.getElement().getPsi();
                if (psiElement == null) {
                    LOG.error("No PSI for folding descriptor " + descriptor);
                    continue;
                }
                if (!docRange.contains(descriptor.getRange())) {
                    diagnoseIncorrectRange(psi, document, language, foldingBuilder, descriptor, psiElement);
                    continue;
                }
                elementsToFoldMap.putValue(psiElement, descriptor);
            }
        }
    }
}
Also used : FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) FoldingBuilder(com.intellij.lang.folding.FoldingBuilder) Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange)

Example 3 with FoldingBuilder

use of com.intellij.lang.folding.FoldingBuilder in project intellij-community by JetBrains.

the class DocumentFoldingInfo method buildRanges.

@NotNull
private static Map<PsiElement, FoldingDescriptor> buildRanges(@NotNull Editor editor, @NotNull PsiFile psiFile) {
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(psiFile.getLanguage());
    final ASTNode node = psiFile.getNode();
    if (node == null)
        return Collections.emptyMap();
    final FoldingDescriptor[] descriptors = LanguageFolding.buildFoldingDescriptors(foldingBuilder, psiFile, editor.getDocument(), true);
    Map<PsiElement, FoldingDescriptor> ranges = new HashMap<>();
    for (FoldingDescriptor descriptor : descriptors) {
        final ASTNode ast = descriptor.getElement();
        final PsiElement psi = ast.getPsi();
        if (psi != null) {
            ranges.put(psi, descriptor);
        }
    }
    return ranges;
}
Also used : FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) FoldingBuilder(com.intellij.lang.folding.FoldingBuilder) ASTNode(com.intellij.lang.ASTNode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FoldingBuilder (com.intellij.lang.folding.FoldingBuilder)3 Language (com.intellij.lang.Language)2 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)2 ASTNode (com.intellij.lang.ASTNode)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 TextRange (com.intellij.openapi.util.TextRange)1 NotNull (org.jetbrains.annotations.NotNull)1