Language (Caret caret, final PsiFile psiFile) { int caretOffset = caret.getOffset(); int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionStart() || caretOffset == caret.getSelectionEnd() ? caret.getSelectionStart() : caretOffset; if (caret.hasSelection()) { return getLanguageAtOffset(psiFile, mostProbablyCorrectLanguageOffset, caret.getSelectionEnd()); } return PsiUtilCore.getLanguageAtOffset(psiFile, mostProbablyCorrectLanguageOffset); }