private void indexUnsavedDocuments(@NotNull final ID<?, ?> indexId,
                                     @Nullable("All projects") Project project,
                                     @Nullable GlobalSearchScope filter,
                                     @Nullable VirtualFile restrictedFile) {
    if (myUpToDateIndicesForUnsavedOrTransactedDocuments.contains(indexId)) {
      return; // no need to index unsaved docs        // todo: we only index files for a project, but this service is app-wide
    }

    Document[] unsavedDocuments = myFileDocumentManager.getUnsavedDocuments();
    Set<Document> transactedDocuments = getTransactedDocuments();
    Document[] uncommittedDocuments = project == null ? Document.EMPTY_ARRAY :
                                      PsiDocumentManager.getInstance(project).getUncommittedDocuments();

    if (unsavedDocuments.length == 0 && uncommittedDocuments.length == 0 && transactedDocuments.isEmpty()) return;

    final Set<Document> documents = new HashSet<>();
    Collections.addAll(documents, unsavedDocuments);
    documents.addAll(transactedDocuments);
    Collections.addAll(documents, uncommittedDocuments);

    LOG.assertTrue(project == null || filter == null || filter.getProject() == null || project.equals(filter.getProject()),
                   "filter should filter files in provided project. ref: 50cf572587cf");
    Collection<Document> documentsToProcessForProject = project == null ? documents :
                                                        ContainerUtil.filter(documents,
                                                                             document -> belongsToScope(
                                                                               myFileDocumentManager.getFile(document), restrictedFile,
                                                                               GlobalSearchScope.everythingScope(project)));

    if (!documentsToProcessForProject.isEmpty()) {
      UpdateTask<Document> task = myRegisteredIndexes.getUnsavedDataUpdateTask(indexId);
      assert task != null : "Task for unsaved data indexing was not initialized for index " + indexId;

      if (myStorageBufferingHandler.runUpdate(true, () -> task.processAll(documentsToProcessForProject, project)) &&
          documentsToProcessForProject.size() == documents.size() &&
          !hasActiveTransactions()
      ) {
        myUpToDateIndicesForUnsavedOrTransactedDocuments.add(indexId);
      }
    }
  }
private void indexUnsavedDocuments(@NotNull final ID<?, ?> indexId,
                                     @Nullable("All projects") Project project,
                                     @Nullable GlobalSearchScope filter,
                                     @Nullable VirtualFile restrictedFile)