Language (final PsiFile file, final Editor editor) { if (file instanceof PsiFileWithOneLanguage) { return file.getLanguage(); } PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); Language language = element != null ? PsiUtilCore.findLanguageFromElement(element) : Language.ANY; if (language != Language.ANY) { return language; } return file.getLanguage(); }