IDEA-80415 Find in path: IDEA seems to check every file when I try to search in...
authorpeter <peter@jetbrains.com>
Fri, 27 Jan 2012 18:51:36 +0000 (19:51 +0100)
committerpeter <peter@jetbrains.com>
Fri, 27 Jan 2012 19:13:52 +0000 (20:13 +0100)
platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java

index 819b3a441e4d801e3379e3255c703a9e6c2b7913..1b594abdc2b10ce5eb7e49108f75853417538319 100644 (file)
@@ -207,7 +207,6 @@ public class FindInProjectUtil {
 
     final Collection<PsiFile> psiFiles = getFilesToSearchIn(findModel, project, psiDirectory);
     try {
-      final SearchScope customScope = findModel.getCustomScope();
       final Set<PsiFile> largeFiles = new THashSet<PsiFile>();
 
       int i = 0;
@@ -377,7 +376,7 @@ public class FindInProjectUtil {
 
       if (fastWords.getFirst() && canOptimizeForFastWordSearch(findModel)) return filesForFastWordSearch;
 
-      final SearchScope customScope = findModel.getCustomScope();
+      final GlobalSearchScope customScope = toGlobal(project, findModel.getCustomScope());
 
       class EnumContentIterator implements ContentIterator {
         final List<PsiFile> myFiles = new ArrayList<PsiFile>(filesForFastWordSearch);
@@ -385,7 +384,9 @@ public class FindInProjectUtil {
 
         @Override
         public boolean processFile(VirtualFile virtualFile) {
-          if (!virtualFile.isDirectory() && (fileMaskRegExp == null || fileMaskRegExp.matcher(virtualFile.getName()).matches()) && (!(customScope instanceof GlobalSearchScope) || ((GlobalSearchScope)customScope).contains(virtualFile))) {
+          if (!virtualFile.isDirectory() &&
+              (fileMaskRegExp == null || fileMaskRegExp.matcher(virtualFile.getName()).matches()) &&
+              (customScope == null || customScope.contains(virtualFile))) {
             final PsiFile psiFile = psiManager.findFile(virtualFile);
             if (psiFile != null && !filesForFastWordSearch.contains(psiFile)) {
               myFiles.add(psiFile);
@@ -439,6 +440,21 @@ public class FindInProjectUtil {
     return true;
   }
 
+  @Nullable
+  private static GlobalSearchScope toGlobal(Project project, @Nullable SearchScope scope) {
+    if (scope instanceof GlobalSearchScope) {
+      return (GlobalSearchScope)scope;
+    }
+    Set<VirtualFile> files = new HashSet<VirtualFile>();
+    for (PsiElement element : ((LocalSearchScope)scope).getScope()) {
+      PsiFile file = element.getContainingFile();
+      if (file != null) {
+        ContainerUtil.addIfNotNull(files, file.getVirtualFile());
+      }
+    }
+    return GlobalSearchScope.filesScope(project, files);
+  }
+
   @NotNull
   private static Pair<Boolean, Collection<PsiFile>> getFilesForFastWordSearch(final FindModel findModel, final Project project,
                                                                final PsiDirectory psiDirectory, final Pattern fileMaskRegExp,