@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 || fileLanguage.getBaseLanguage() == lineStartLanguage // file language is a more specific dialect of the line // language ? fileLanguage : lineStartLanguage; if (viewProvider instanceof TemplateLanguageFileViewProvider && lang == ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage()) { lang = viewProvider.getBaseLanguage(); } return LanguageCommenters.INSTANCE.forLanguage(lang); }
private static boolean defaultFunctionalityWorked(final PsiLanguageInjectionHost host) { final THashSet<String> languages = new THashSet<String>(); final List<Pair<PsiElement, TextRange>> files = InjectedLanguageUtil.getInjectedPsiFiles(host); if (files == null) return false; for (Pair<PsiElement, TextRange> pair : files) { for (Language lang = pair.first.getLanguage(); lang != null; lang = lang.getBaseLanguage()) { languages.add(lang.getID()); } } // todo there is a problem: host i.e. literal expression is confused with "target" i.e. // parameter // todo therefore this part doesn't work for java return Configuration.getInstance().setHostInjectionEnabled(host, languages, false); }
@Override public FoldingBuilder forLanguage(Language l) { FoldingBuilder cached = l.getUserData(getLanguageCache()); if (cached != null) return cached; List<FoldingBuilder> extensions = forKey(l); FoldingBuilder result; if (extensions.isEmpty()) { Language base = l.getBaseLanguage(); if (base != null) { result = forLanguage(base); } else { result = getDefaultImplementation(); } } else { return (extensions.size() == 1) ? extensions.get(0) : myBuilder == null ? myBuilder = new CompositeFoldingBuilder(extensions) : myBuilder; } l.putUserData(getLanguageCache(), result); return result; }