void indexUnsavedDocument(@NotNull final Document document,
                            @NotNull final ID<?, ?> requestedIndexId,
                            @NotNull Project project,
                            @NotNull final VirtualFile vFile) {
    PsiFile dominantContentFile = findLatestKnownPsiForUncomittedDocument(document, project);

    DocumentContent content = findLatestContent(document, dominantContentFile);

    long currentDocStamp = PsiDocumentManager.getInstance(project).getLastCommittedStamp(document);

    long previousDocStamp = myLastIndexedDocStamps.get(document, requestedIndexId);
    if (previousDocStamp == currentDocStamp) return;

    final CharSequence contentText = content.getText();
    FileTypeManagerEx.getInstanceEx().freezeFileTypeTemporarilyIn(vFile, () -> {
      IndexedFileImpl indexedFile = new IndexedFileImpl(vFile, project);
      if (getRequiredIndexes(indexedFile).contains(requestedIndexId)) {
        int inputId = getFileId(vFile);

        if (!isTooLarge(vFile, (long)contentText.length())) {
          FileContentImpl newFc = getUnsavedDocContent(document, project, vFile, currentDocStamp, contentText);
          tuneFileContent(document, dominantContentFile, content, newFc);

          markFileIndexed(vFile, newFc);
          try {
            updateIndexInNonCancellableSection(requestedIndexId, inputId, newFc);
          }
          finally {
            unmarkBeingIndexed();
            cleanFileContent(newFc, dominantContentFile);
          }
        }
        else { // effectively wipe the data from the indices
          updateIndexInNonCancellableSection(requestedIndexId, inputId, null);
        }
      }

      long previousState = myLastIndexedDocStamps.set(document, requestedIndexId, currentDocStamp);
      assert previousState == previousDocStamp;
    });
  }
void indexUnsavedDocument(@NotNull final Document document,
                            @NotNull final ID<?, ?> requestedIndexId,
                            @NotNull Project project,
                            @NotNull final VirtualFile vFile)