public static @Nullable Language getLanguageInEditor(@NotNull Caret caret, final @NotNull Project project) {
    Editor editor = caret.getEditor();
    assertEditorAndProjectConsistent(project, editor);
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

    if (file == null) {
      return null;
    }

    if (file instanceof PsiFileWithOneLanguage) {
      return file.getLanguage();
    }

    @NotNull TextRange selection = caret.getSelectionRange();
    int mostProbablyCorrectLanguageOffset = selection.getStartOffset();
    PsiElement elt = getElementAtOffset(file, mostProbablyCorrectLanguageOffset);
    Language lang = findLanguageFromElement(elt);

    if (caret.hasSelection()) {
      lang = evaluateLanguageInRange(selection, file);
    }

    return narrowLanguage(lang, file.getLanguage());
  }
public static @Nullable Language getLanguageInEditor(@NotNull Caret caret, final @NotNull Project project)