private @Nullable GlobalSearchScope buildScopeWithReferences(@Nullable Set<VirtualFile> referentFiles, @NotNull PsiElement element) {
    if (referentFiles == null) return null;

    GlobalSearchScope referencesScope = GlobalSearchScope.filesWithoutLibrariesScope(project, referentFiles);

    GlobalSearchScope knownDirtyScope = myDirtyScopeHolder.getDirtyScope();
    GlobalSearchScope wholeClearScope = GlobalSearchScope.notScope(knownDirtyScope);
    GlobalSearchScope knownCleanScope = GlobalSearchScope.getScopeRestrictedByFileTypes(wholeClearScope, myFileTypes.toArray(FileType.EMPTY_ARRAY));
    GlobalSearchScope wholeDirtyScope = GlobalSearchScope.notScope(knownCleanScope);
    GlobalSearchScope mayContainReferencesScope = referencesScope.uniteWith(wholeDirtyScope);
    return scopeWithLibraryIfNeeded(project, myProjectFileIndex, mayContainReferencesScope, element);
  }
private @Nullable GlobalSearchScope buildScopeWithReferences(@Nullable Set<VirtualFile> referentFiles, @NotNull PsiElement element)