IDEA-136816 Find in Path restricted to module scope does not search non-source paths

This commit is contained in:
peter
2015-02-24 12:21:02 +01:00
parent 1555db7819
commit 1157c15d8e
4 changed files with 36 additions and 19 deletions
@@ -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));
}
@@ -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>();
@@ -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);
}
}
@@ -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());
}
}