Language (@NotNull PsiElement element) { PsiFile containingFile = element.getContainingFile(); FileViewProvider provider = containingFile.getViewProvider(); Set<Language> languages = provider.getLanguages(); if (languages.size() > 1) { Language language = containingFile.getLanguage(); if (languages.contains(language)) { return language; } } return provider.getBaseLanguage(); }