@Override
  public void scheduleReformatWhenSettingsComputed(@NotNull PsiFile file) {
    if (LightVirtualFile.shouldSkipEventSystem(file.getViewProvider().getVirtualFile())) {
      ensureDocumentCommitted(file);
      formatBlockingPostprocess(file);
      return;
    }

    final Runnable commandRunnable = () -> {
      if (file.isValid()) {
        WriteCommandAction.runWriteCommandAction(
          myProject, CodeStyleBundle.message("command.name.reformat"), null, () -> formatBlockingPostprocess(file), file);
      }
    };

    CodeStyleCachingService.getInstance(myProject).scheduleWhenSettingsComputed(
      file,
      () -> {
        NonBlockingReadAction<CodeFormattingData> prepareDataAction = ReadAction.nonBlocking(
            () -> {
              return CodeFormattingData.prepare(file, Collections.singletonList(file.getTextRange()));
            }
          )
          .expireWhen(() -> myProject.isDisposed())
          .withDocumentsCommitted(myProject);

        if (ApplicationManager.getApplication().isUnitTestMode()) {
          ensureDocumentCommitted(file);
          commandRunnable.run();
        }
        else if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
          PsiDocumentManager.getInstance(myProject).commitAllDocuments();
          prepareDataAction.executeSynchronously();
          commandRunnable.run();
        }
        else {
          prepareDataAction
            .finishOnUiThread(ModalityState.nonModal(), data -> commandRunnable.run())
            .submit(AppExecutorUtil.getAppExecutorService());
        }
      }
    );
  }
@Override
  public void scheduleReformatWhenSettingsComputed(@NotNull PsiFile file)