Search in sources :

Example 1 with SimpleTemplateLanguageFormattingModelBuilder

use of com.intellij.psi.templateLanguages.SimpleTemplateLanguageFormattingModelBuilder in project idea-handlebars by dmarcotte.

the class HbFormattingModelBuilder method createModel.

/**
   * We have to override {@link com.intellij.formatting.templateLanguages.TemplateLanguageFormattingModelBuilder#createModel}
   * since after we delegate to some templated languages, those languages (xml/html for sure, potentially others)
   * delegate right back to us to format the HbTokenTypes.OUTER_ELEMENT_TYPE token we tell them to ignore,
   * causing an stack-overflowing loop of polite format-delegation.
   */
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    if (!HbConfig.isFormattingEnabled()) {
        // to the templated language, which lets the users manage that separately)
        return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
    }
    final PsiFile file = element.getContainingFile();
    Block rootBlock;
    ASTNode node = element.getNode();
    if (node.getElementType() == HbTokenTypes.OUTER_ELEMENT_TYPE) {
        // language.  Make a dummy block to allow that formatter to continue
        return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
    } else {
        rootBlock = getRootBlock(file, file.getViewProvider(), settings);
    }
    return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file);
}
Also used : DocumentBasedFormattingModel(com.intellij.psi.formatter.DocumentBasedFormattingModel) SimpleTemplateLanguageFormattingModelBuilder(com.intellij.psi.templateLanguages.SimpleTemplateLanguageFormattingModelBuilder) ASTNode(com.intellij.lang.ASTNode) SyntheticBlock(com.intellij.psi.formatter.xml.SyntheticBlock) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SimpleTemplateLanguageFormattingModelBuilder

use of com.intellij.psi.templateLanguages.SimpleTemplateLanguageFormattingModelBuilder in project intellij-plugins by JetBrains.

the class HbFormattingModelBuilder method createModel.

/**
   * We have to override {@link com.intellij.formatting.templateLanguages.TemplateLanguageFormattingModelBuilder#createModel}
   * since after we delegate to some templated languages, those languages (xml/html for sure, potentially others)
   * delegate right back to us to format the HbTokenTypes.OUTER_ELEMENT_TYPE token we tell them to ignore,
   * causing an stack-overflowing loop of polite format-delegation.
   */
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    if (!HbConfig.isFormattingEnabled()) {
        // to the templated language, which lets the users manage that separately)
        return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
    }
    final PsiFile file = element.getContainingFile();
    Block rootBlock;
    ASTNode node = element.getNode();
    if (node.getElementType() == HbTokenTypes.OUTER_ELEMENT_TYPE) {
        // language.  Make a dummy block to allow that formatter to continue
        return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
    } else {
        rootBlock = getRootBlock(file, file.getViewProvider(), settings);
    }
    return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file);
}
Also used : DocumentBasedFormattingModel(com.intellij.psi.formatter.DocumentBasedFormattingModel) SimpleTemplateLanguageFormattingModelBuilder(com.intellij.psi.templateLanguages.SimpleTemplateLanguageFormattingModelBuilder) ASTNode(com.intellij.lang.ASTNode) AbstractBlock(com.intellij.psi.formatter.common.AbstractBlock) SyntheticBlock(com.intellij.psi.formatter.xml.SyntheticBlock) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ASTNode (com.intellij.lang.ASTNode)2 PsiFile (com.intellij.psi.PsiFile)2 DocumentBasedFormattingModel (com.intellij.psi.formatter.DocumentBasedFormattingModel)2 SyntheticBlock (com.intellij.psi.formatter.xml.SyntheticBlock)2 SimpleTemplateLanguageFormattingModelBuilder (com.intellij.psi.templateLanguages.SimpleTemplateLanguageFormattingModelBuilder)2 NotNull (org.jetbrains.annotations.NotNull)2 AbstractBlock (com.intellij.psi.formatter.common.AbstractBlock)1