@Override
  public void buildLanguageFoldRegions(@NotNull List<FoldingDescriptor> foldings,
                                       @NotNull PsiElement psiElement,
                                       @NotNull Document document,
                                       boolean quick) {
    XmlDocument xmlDocument;

    if (psiElement instanceof XmlFile file) {
      xmlDocument = file.getDocument();
    }
    else if (psiElement instanceof XmlDocument) {
      xmlDocument = (XmlDocument)psiElement;
    } else {
      // handle embedded templates
      xmlDocument = PsiTreeUtil.getChildOfType(psiElement, XmlDocument.class);
    }

    XmlElement rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
    if (rootTag == null) {
      rootTag = xmlDocument;
    }

    if (rootTag != null) {
      doAddForChildren(xmlDocument, foldings, document);
    }
  }
@Override
  public void buildLanguageFoldRegions(@NotNull List<FoldingDescriptor> foldings,
                                       @NotNull PsiElement psiElement,
                                       @NotNull Document document,
                                       boolean quick)