private static @NotNull Language evaluateLanguageInRange(TextRange selectionRange, @NotNull PsiFile file) {
    PsiElement elt = getElementAtOffset(file, selectionRange.getStartOffset());

    while (true) {
      if (elt instanceof PsiFile) {
        return elt.getLanguage();
      }
      PsiElement parent = elt.getParent();
      TextRange range = elt.getTextRange();
      if (range == null) {
        LOG.error("Range is null for " + elt + "; " + elt.getClass());
        return file.getLanguage();
      }
      if (range.contains(selectionRange) || parent == null) {
        return elt.getLanguage();
      }
      elt = parent;
    }
  }
private static @NotNull Language evaluateLanguageInRange(TextRange selectionRange, @NotNull PsiFile file)