private void submitInBackground(@NotNull FileEditor fileEditor,
                                  @NotNull Document document,
                                  @NotNull VirtualFile virtualFile,
                                  @NotNull PsiFile psiFile,
                                  @NotNull BackgroundEditorHighlighter backgroundEditorHighlighter,
                                  int @NotNull [] passesToIgnore,
                                  @NotNull DaemonProgressIndicator progress,
                                  @NotNull HighlightingSessionImpl session) {
    ApplicationManager.getApplication().assertIsNonDispatchThread();
    if (myProject.isDisposed()) {
      stopProcess(false, "project disposed");
      return;
    }
    if (progress.isCanceled()) {
      stopProcess(true, "canceled in queuePassesCreation: "+progress.getCancellationTrace());
      return;
    }
    if (getPsiDocumentManager().hasEventSystemEnabledUncommittedDocuments()) {
      stopProcess(true, "more documents to commit: " + ReadAction.compute(() -> Arrays.toString(getPsiDocumentManager().getUncommittedDocuments())));
      return;
    }
    try {
      ProgressManager.getInstance().executeProcessUnderProgress(Context.current().wrap(() -> {
        // wait for heavy processing to stop, re-schedule daemon but not too soon
        boolean heavyProcessIsRunning = heavyProcessIsRunning();
        HighlightingPass[] passes = ReadAction.compute(() -> {
          if (myProject.isDisposed() || !fileEditor.isValid() || !psiFile.isValid()) {
            return HighlightingPass.EMPTY_ARRAY;
          }
          // remove obsolete infos for invalid psi elements as soon as possible, before highlighting passes start
          ((HighlightInfoUpdaterImpl)HighlightInfoUpdater.getInstance(myProject)).removeInvalidPsiElements(psiFile, this, session);
          if (session.isCanceled()) {
            // editor or something was changed between commit document notification in EDT and this point in the FJP thread
            throw new ProcessCanceledException();
          }
          session.additionalSetupFromBackground(psiFile);
          try (AccessToken ignored = ClientId.withClientId(ClientFileEditorManager.getClientId(fileEditor))) {
            HighlightingPass[] r = backgroundEditorHighlighter instanceof TextEditorBackgroundHighlighter textHighlighter ?
                                   textHighlighter.getPasses(passesToIgnore).toArray(HighlightingPass.EMPTY_ARRAY) :
                                   backgroundEditorHighlighter.createPassesForEditor();
            if (heavyProcessIsRunning) {
              r = ContainerUtil.findAllAsArray(r, o -> DumbService.isDumbAware(o));
            }
            return r;
          }
        });
        boolean hasPasses = passes.length != 0;
        if (!hasPasses) {
          // will be re-scheduled by HeavyLatch listener in DaemonListeners
          return;
        }
        // synchronize on TextEditorHighlightingPassRegistrarImpl instance to avoid concurrent modification of TextEditorHighlightingPassRegistrarImpl.nextAvailableId
        synchronized (TextEditorHighlightingPassRegistrar.getInstance(myProject)) {
          myPassExecutorService.submitPasses(document, virtualFile, psiFile, fileEditor, passes, progress);
        }
      }), progress);
    }
    catch (ProcessCanceledException e) {
      LOG.debug(e);
      stopProcess(true, "PCE in queuePassesCreation");
    }
    catch (Throwable e) {
      // make it manifestable in tests
      PassExecutorService.saveException(e, progress);
      throw e;
    }
  }
private void submitInBackground(@NotNull FileEditor fileEditor,
                                  @NotNull Document document,
                                  @NotNull VirtualFile virtualFile,
                                  @NotNull PsiFile psiFile,
                                  @NotNull BackgroundEditorHighlighter backgroundEditorHighlighter,
                                  int @NotNull [] passesToIgnore,
                                  @NotNull DaemonProgressIndicator progress,
                                  @NotNull HighlightingSessionImpl session)