From 1157c15d8e1caf782e3c35efb78137bb6cf72ae9 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 24 Feb 2015 11:24:03 +0100 Subject: [PATCH] IDEA-136816 Find in Path restricted to module scope does not search non-source paths --- .../com/intellij/find/FindManagerTest.java | 15 +++++++++++++++ .../com/intellij/find/impl/FindInProjectTask.java | 14 ++------------ .../com/intellij/find/impl/FindInProjectUtil.java | 11 ++++------- .../usages/impl/UsageViewManagerTest.java | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java index 8bf2fb1d4284..384fdc3eb339 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java @@ -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)); } diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectTask.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectTask.java index 93e88a25e0fa..973be2bc7416 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectTask.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectTask.java @@ -267,7 +267,7 @@ class FindInProjectTask { @NotNull private Collection collectFilesInScope(@NotNull final Set 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 resultFiles = new LinkedHashSet(); diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java index 17ca7e4436bf..d22071e66b8e 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java @@ -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); } } diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java index 3e38bd2bbb4a..a4fd1b4c881b 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java @@ -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()); + } }