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)");
findModel.setFromCursor(false);
findModel.setGlobal(true);
findModel.setMultipleFiles(true);
+ findModel.setCustomScope(true);
ThrowableRunnable test = new ThrowableRunnable() {
@Override
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));
}
@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);
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>();
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;
}
@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();
// 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);
}
}
import com.intellij.usages.UsageViewManager;
public class UsageViewManagerTest extends PlatformTestCase {
+
+ static {
+ initPlatformLangPrefix();
+ }
+
public void testScopeCreatedForFindInDirectory() {
VirtualFile dir = getProject().getBaseDir();
FindModel findModel = new FindModel();
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());
+ }
}