Language (@NotNull PsiFile file) { FileViewProvider vp = file.getViewProvider(); Set<Language> languages = vp.getLanguages(); for (Language language : languages) { if (file.equals(vp.getPsi(language))) { return language; } } throw new AssertionError("Non-retrievable file: " + file.getClass() + "; " + file.getLanguage() + "; " + languages); }