Search in sources :

Example 6 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class CommentByBlockCommentHandler method getCommenter.

@Nullable
public static Commenter getCommenter(final PsiFile file, final Editor editor, final Language lineStartLanguage, final Language lineEndLanguage) {
    final FileViewProvider viewProvider = file.getViewProvider();
    for (MultipleLangCommentProvider provider : MultipleLangCommentProvider.EP_NAME.getExtensions()) {
        if (provider.canProcess(file, viewProvider)) {
            return provider.getLineCommenter(file, editor, lineStartLanguage, lineEndLanguage);
        }
    }
    final Language fileLanguage = file.getLanguage();
    Language lang = lineStartLanguage == null || LanguageCommenters.INSTANCE.forLanguage(lineStartLanguage) == null || // file language is a more specific dialect of the line language
    fileLanguage.getBaseLanguage() == lineStartLanguage ? fileLanguage : lineStartLanguage;
    if (viewProvider instanceof TemplateLanguageFileViewProvider && lang == ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage()) {
        lang = viewProvider.getBaseLanguage();
    }
    return LanguageCommenters.INSTANCE.forLanguage(lang);
}
Also used : TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) Language(com.intellij.lang.Language) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) MultipleLangCommentProvider(com.intellij.psi.templateLanguages.MultipleLangCommentProvider) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class TemplateLanguageFormattingModelBuilder method getRootBlock.

protected Block getRootBlock(PsiElement element, FileViewProvider viewProvider, CodeStyleSettings settings) {
    ASTNode node = element.getNode();
    if (node == null) {
        return createDummyBlock(node);
    }
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
        final Language dataLanguage = ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage();
        final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(dataLanguage);
        if (builder instanceof DelegatingFormattingModelBuilder && ((DelegatingFormattingModelBuilder) builder).dontFormatMyModel()) {
            return createDummyBlock(node);
        }
        if (builder != null) {
            final FormattingModel model = builder.createModel(viewProvider.getPsi(dataLanguage), settings);
            List<DataLanguageBlockWrapper> childWrappers = buildChildWrappers(model.getRootBlock());
            if (childWrappers.size() == 1) {
                childWrappers = buildChildWrappers(childWrappers.get(0).getOriginal());
            }
            return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, filterBlocksByRange(childWrappers, node.getTextRange()), settings);
        }
    }
    return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, Collections.<DataLanguageBlockWrapper>emptyList(), settings);
}
Also used : DocumentBasedFormattingModel(com.intellij.psi.formatter.DocumentBasedFormattingModel) Language(com.intellij.lang.Language) ASTNode(com.intellij.lang.ASTNode) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)

Example 8 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class InspectionProfileEntry method getSuppressors.

@NotNull
public static Set<InspectionSuppressor> getSuppressors(@NotNull PsiElement element) {
    FileViewProvider viewProvider = element.getContainingFile().getViewProvider();
    final InspectionSuppressor elementLanguageSuppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(element.getLanguage());
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
        Set<InspectionSuppressor> suppressors = new LinkedHashSet<>();
        ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(viewProvider.getBaseLanguage()));
        for (Language language : viewProvider.getLanguages()) {
            ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(language));
        }
        ContainerUtil.addIfNotNull(suppressors, elementLanguageSuppressor);
        return suppressors;
    }
    if (!element.getLanguage().isKindOf(viewProvider.getBaseLanguage())) {
        // handling embedding elements {@link EmbeddingElementType
        Set<InspectionSuppressor> suppressors = new LinkedHashSet<>();
        ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(viewProvider.getBaseLanguage()));
        ContainerUtil.addIfNotNull(suppressors, elementLanguageSuppressor);
        return suppressors;
    }
    return elementLanguageSuppressor != null ? Collections.singleton(elementLanguageSuppressor) : Collections.emptySet();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class TemplateLanguageStructureViewBuilder method createStructureView.

@Override
@NotNull
public StructureView createStructureView(FileEditor fileEditor, @NotNull Project project) {
    myFileEditor = fileEditor;
    List<StructureViewComposite.StructureViewDescriptor> viewDescriptors = new ArrayList<>();
    final FileViewProvider provider = getViewProvider();
    assert provider != null : myVirtualFile;
    final StructureViewComposite.StructureViewDescriptor structureViewDescriptor = createMainView(fileEditor, provider.getPsi(provider.getBaseLanguage()));
    if (structureViewDescriptor != null)
        viewDescriptors.add(structureViewDescriptor);
    myBaseLanguageViewDescriptorIndex = -1;
    updateTemplateDataFileView();
    if (myBaseStructureViewDescriptor != null) {
        viewDescriptors.add(myBaseStructureViewDescriptor);
        myBaseLanguageViewDescriptorIndex = viewDescriptors.size() - 1;
    }
    if (provider instanceof TemplateLanguageFileViewProvider) {
        final Language dataLanguage = ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage();
        for (final Language language : provider.getLanguages()) {
            if (language != dataLanguage && language != provider.getBaseLanguage()) {
                ContainerUtil.addIfNotNull(viewDescriptors, createBaseLanguageStructureView(fileEditor, language));
            }
        }
    }
    StructureViewComposite.StructureViewDescriptor[] array = viewDescriptors.toArray(new StructureViewComposite.StructureViewDescriptor[viewDescriptors.size()]);
    myStructureViewComposite = new StructureViewComposite(array);
    project.getMessageBus().connect(myStructureViewComposite).subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() {

        final Alarm alarm = new Alarm(myStructureViewComposite);

        @Override
        public void modificationCountChanged() {
            alarm.cancelAllRequests();
            alarm.addRequest(() -> updateAfterPsiChange(), 300, ModalityState.NON_MODAL);
        }
    });
    return myStructureViewComposite;
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) ArrayList(java.util.ArrayList) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) Language(com.intellij.lang.Language) Alarm(com.intellij.util.Alarm) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with TemplateLanguageFileViewProvider

use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.

the class StructureViewElementWrapper method getNavigatableInTemplateLanguageFile.

@Nullable
private Navigatable getNavigatableInTemplateLanguageFile() {
    PsiElement element = (PsiElement) myTreeElement.getValue();
    if (element == null)
        return null;
    int offset = element.getTextRange().getStartOffset();
    final Language dataLanguage = ((TemplateLanguageFileViewProvider) myMainFile.getViewProvider()).getTemplateDataLanguage();
    final PsiFile dataFile = myMainFile.getViewProvider().getPsi(dataLanguage);
    if (dataFile == null)
        return null;
    PsiElement tlElement = dataFile.findElementAt(offset);
    while (true) {
        if (tlElement == null || tlElement.getTextRange().getStartOffset() != offset)
            break;
        if (tlElement instanceof Navigatable) {
            return (Navigatable) tlElement;
        }
        tlElement = tlElement.getParent();
    }
    return null;
}
Also used : Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)13 Language (com.intellij.lang.Language)11 PsiFile (com.intellij.psi.PsiFile)6 FileViewProvider (com.intellij.psi.FileViewProvider)5 PsiElement (com.intellij.psi.PsiElement)4 XMLLanguage (com.intellij.lang.xml.XMLLanguage)3 Project (com.intellij.openapi.project.Project)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 XHTMLLanguage (com.intellij.lang.xhtml.XHTMLLanguage)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 InspectionProfile (com.intellij.codeInspection.InspectionProfile)1 LocalQuickFixOnPsiElement (com.intellij.codeInspection.LocalQuickFixOnPsiElement)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 XHtmlFileType (com.intellij.ide.highlighter.XHtmlFileType)1 XmlFileType (com.intellij.ide.highlighter.XmlFileType)1 ASTNode (com.intellij.lang.ASTNode)1 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 FileType (com.intellij.openapi.fileTypes.FileType)1