void () { final MatchContext matchContext = getMatchContext(); final MatchOptions options = matchContext.getOptions(); final CompiledPattern compiledPattern = matchContext.getPattern(); SearchScope searchScope = compiledPattern.getScope(); final boolean ourOptimizedScope = searchScope != null; if (!ourOptimizedScope) searchScope = options.getScope(); if (searchScope instanceof GlobalSearchScope) { final GlobalSearchScope scope = (GlobalSearchScope)searchScope; final ContentIterator ci = fileOrDir -> { if (!fileOrDir.isDirectory() && scope.contains(fileOrDir) && !FileTypeRegistry.getInstance().isFileOfType(fileOrDir, FileTypes.UNKNOWN)) { ++totalFilesToScan; scheduler.addOneTask(new MatchOneVirtualFile(fileOrDir)); } return true; }; final ProgressIndicator progress = matchContext.getSink().getProgressIndicator(); ReadAction.run(() -> FileBasedIndex.getInstance().iterateIndexableFiles(ci, project, progress)); if (progress != null) progress.setText2(""); } else { final LocalSearchScope scope = (LocalSearchScope)searchScope; assert scope != null; final PsiElement[] elementsToScan = scope.getScope(); totalFilesToScan = elementsToScan.length; for (int i = 0; i < elementsToScan.length; ++i) { final PsiElement psiElement = elementsToScan[i]; if (psiElement == null) continue; scheduler.addOneTask(new MatchOnePsiFile(psiElement)); if (ourOptimizedScope) elementsToScan[i] = null; // to prevent long PsiElement reference } } }