@Nullable
  public static <T> T updateDocumentUnblockedAndCommitted(@NotNull PsiElement anchor, @NotNull Function<? super Document, ? extends T> func) {
    final PsiDocumentManager manager = PsiDocumentManager.getInstance(anchor.getProject());
    // manager.getDocument(anchor.getContainingFile()) doesn't work with intention preview
    final Document document = anchor.getContainingFile().getViewProvider().getDocument();
    if (document != null) {
      manager.doPostponedOperationsAndUnblockDocument(document);
      try {
        return func.fun(document);
      }
      finally {
        manager.commitDocument(document);
      }
    }
    return null;
  }
@Nullable
  public static <T> T updateDocumentUnblockedAndCommitted(@NotNull PsiElement anchor, @NotNull Function<? super Document, ? extends T> func)