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);
}
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);
}
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();
}
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;
}
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;
}
Aggregations