int (@NotNull PsiFile file) { FileViewProvider provider = file.getViewProvider(); Set<Language> languages = provider.getLanguages(); if (languages.size() == 1) { return 0; } List<Language> array = new ArrayList<>(languages); array.sort(PsiUtilBase.LANGUAGE_COMPARATOR); for (int i = 0; i < array.size(); i++) { Language language = array.get(i); if (provider.getPsi(language) == file) return i; } throw new RuntimeException("Cannot find root for: " + file); }