@Override
  public @Nullable CodeFoldingState buildInitialFoldings(final @NotNull Document document) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    ApplicationManager.getApplication().assertIsNonDispatchThread();

    if (myProject.isDisposed()) {
      return null;
    }
    PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject);
    if (psiDocumentManager.isUncommited(document)) {
      // skip building foldings for an uncommitted document, CodeFoldingPass invoked by daemon will do it later
      return null;
    }
    //Do not save/restore folding for code fragments
    final PsiFile file = psiDocumentManager.getPsiFile(document);
    if (file == null || !file.isValid() || !file.getViewProvider().isPhysical() && !ApplicationManager.getApplication().isUnitTestMode()) {
      return null;
    }

    FoldingState zombie = raiseZombie(document, file);
    List<RegionInfo> regionInfos = FoldingUpdate.getFoldingsFor(file, true);

    boolean supportsDumbModeFolding = FoldingUpdate.supportsDumbModeFolding(file);

    return editor -> {
      ThreadingAssertions.assertEventDispatchThread();
      if (myProject.isDisposed() || editor.isDisposed()) return;
      final FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel();
      if (!foldingModel.isFoldingEnabled()) return;
      if (isFoldingsInitializedInEditor(editor)) return;
      if (DumbService.isDumb(myProject) && !supportsDumbModeFolding) return;
      if (zombie != null) {
        boolean applied = zombie.applyState(document, foldingModel);
        if (!applied) {
          updateAndInitFolding(editor, foldingModel, file, regionInfos);
        }
      }
      else {
        updateAndInitFolding(editor, foldingModel, file, regionInfos);
      }
    };
  }
@Override
  public @Nullable CodeFoldingState buildInitialFoldings(final @NotNull Document document)