IDEA-136816 Find in Path restricted to module scope does not search non-source paths
authorpeter <peter@jetbrains.com>
Tue, 24 Feb 2015 10:24:03 +0000 (11:24 +0100)
committerpeter <peter@jetbrains.com>
Tue, 24 Feb 2015 11:21:02 +0000 (12:21 +0100)
java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
platform/lang-impl/src/com/intellij/find/impl/FindInProjectTask.java
platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java
platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java

index 8bf2fb1d4284c3974ac7cd1f105f82c27bf7aa26..384fdc3eb3391def12e6080ddc396712e53916e7 100644 (file)
@@ -365,6 +365,19 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
     assertSize(1, findUsages(findModel));
   }
 
+  public void testNonSourceContent() throws Exception {
+    VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTempDirectory());
+    PsiTestUtil.addContentRoot(myModule, root);
+
+    createFile(myModule, root, "A.txt", "goo doo");
+
+    FindModel findModel = FindManagerTestUtils.configureFindModel("goo");
+    findModel.setProjectScope(false);
+    findModel.setModuleName(myModule.getName());
+
+    assertSize(1, findUsages(findModel));
+  }
+
   public void testReplaceRegexp() {
     FindModel findModel = new FindModel();
     findModel.setStringToFind("bug_(?=here)");
@@ -537,6 +550,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
       findModel.setFromCursor(false);
       findModel.setGlobal(true);
       findModel.setMultipleFiles(true);
+      findModel.setCustomScope(true);
 
       ThrowableRunnable test = new ThrowableRunnable() {
         @Override
@@ -573,6 +587,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
       VirtualFile file = tempDirFixture.createFile("a.txt", "foo bar foo");
       FindModel findModel = FindManagerTestUtils.configureFindModel("foo");
       findModel.setWholeWordsOnly(true);
+      findModel.setCustomScope(true);
       findModel.setCustomScope(new LocalSearchScope(PsiManager.getInstance(myProject).findFile(file)));
       assertSize(2, findUsages(findModel));
     }
index 93e88a25e0fa675b062c424161ad217b1953d92d..973be2bc7416137dc1e152fa53a0900eb72c6f7e 100644 (file)
@@ -267,7 +267,7 @@ class FindInProjectTask {
 
   @NotNull
   private Collection<VirtualFile> collectFilesInScope(@NotNull final Set<VirtualFile> alreadySearched, final boolean skipIndexed) {
-    SearchScope customScope = myFindModel.getCustomScope();
+    SearchScope customScope = myFindModel.isCustomScope() ? myFindModel.getCustomScope() : null;
     final GlobalSearchScope globalCustomScope = toGlobal(customScope);
 
     final ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
@@ -432,17 +432,7 @@ class FindInProjectTask {
       return Collections.emptySet();
     }
 
-    SearchScope customScope = myFindModel.getCustomScope();
-    GlobalSearchScope scope = myPsiDirectory != null
-                              ? GlobalSearchScopesCore.directoryScope(myPsiDirectory, myFindModel.isWithSubdirectories())
-                              : myModule != null
-                                ? myModule.getModuleContentScope()
-                                : customScope instanceof GlobalSearchScope
-                                  ? (GlobalSearchScope)customScope
-                                  : toGlobal(customScope);
-    if (scope == null) {
-      scope = ProjectScope.getContentScope(myProject);
-    }
+    GlobalSearchScope scope = toGlobal(FindInProjectUtil.getScopeFromModel(myProject, myFindModel));
 
     final Set<VirtualFile> resultFiles = new LinkedHashSet<VirtualFile>();
 
index 17ca7e4436bf2f1332a9991bbbadc83c91f7df70..d22071e66b8eb510977153fc220dd1ca73c49da8 100644 (file)
@@ -49,10 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.openapi.vfs.ex.VirtualFileManagerEx;
 import com.intellij.psi.*;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.psi.search.GlobalSearchScopesCore;
-import com.intellij.psi.search.LocalSearchScope;
-import com.intellij.psi.search.SearchScope;
+import com.intellij.psi.search.*;
 import com.intellij.ui.content.Content;
 import com.intellij.usageView.UsageInfo;
 import com.intellij.usageView.UsageViewManager;
@@ -443,7 +440,7 @@ public class FindInProjectUtil {
   }
 
   @NotNull
-  private static SearchScope getScopeFromModel(@NotNull Project project, @NotNull FindModel findModel) {
+  static SearchScope getScopeFromModel(@NotNull Project project, @NotNull FindModel findModel) {
     SearchScope customScope = findModel.getCustomScope();
     PsiDirectory psiDir = getPsiDirectory(findModel, project);
     VirtualFile directory = psiDir == null ? null : psiDir.getVirtualFile();
@@ -452,8 +449,8 @@ public class FindInProjectUtil {
            // we don't have to check for myProjectFileIndex.isExcluded(file) here like FindInProjectTask.collectFilesInScope() does
            // because all found usages are guaranteed to be not in excluded dir
            directory != null ? GlobalSearchScopesCore.directoryScope(project, directory, findModel.isWithSubdirectories()) :
-           module != null ? GlobalSearchScope.moduleScope(module) :
-           findModel.isProjectScope() ? GlobalSearchScope.projectScope(project) :
+           module != null ? module.getModuleContentScope() :
+           findModel.isProjectScope() ? ProjectScope.getContentScope(project) :
            GlobalSearchScope.allScope(project);
   }
 }
index 3e38bd2bbb4a0b8fbf7fed71a889e76261bcd43d..a4fd1b4c881b79dad068c603db0083a10b668b45 100644 (file)
@@ -25,6 +25,11 @@ import com.intellij.usages.UsageTarget;
 import com.intellij.usages.UsageViewManager;
 
 public class UsageViewManagerTest extends PlatformTestCase {
+
+  static {
+    initPlatformLangPrefix();
+  }
+
   public void testScopeCreatedForFindInDirectory() {
     VirtualFile dir = getProject().getBaseDir();
     FindModel findModel = new FindModel();
@@ -36,4 +41,14 @@ public class UsageViewManagerTest extends PlatformTestCase {
     SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[]{target});
     assertEquals(scope, GlobalSearchScopesCore.directoryScope(getProject(), dir, true));
   }
+
+  public void testScopeCreatedForFindInModuleContent() {
+    FindModel findModel = new FindModel();
+    findModel.setModuleName(getModule().getName());
+    findModel.setProjectScope(false);
+    UsageTarget target = new FindInProjectUtil.StringUsageTarget(getProject(), findModel);
+    UsageViewManagerImpl manager = (UsageViewManagerImpl)UsageViewManager.getInstance(getProject());
+    SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[]{target});
+    assertEquals(scope, getModule().getModuleContentScope());
+  }
 }