mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-126598 Find in open files does not find occurrences in files outside of project
This commit is contained in:
@@ -18,9 +18,12 @@ package com.intellij.psi.search;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -30,8 +33,15 @@ public class GlobalSearchScopes extends GlobalSearchScopesCore {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope openFilesScope(@NotNull Project project) {
|
||||
public static SearchScope openFilesScope(@NotNull Project project) {
|
||||
final VirtualFile[] files = FileEditorManager.getInstance(project).getOpenFiles();
|
||||
return GlobalSearchScope.filesScope(project, Arrays.asList(files), "Open Files");
|
||||
// We can not use GlobalSearchScope as it is usually bound to project and used via filtering of project / library roots
|
||||
// Open files can be out of project roots e.g. arbitrary open file so we go LocalSearchScope way, filled with elements to process
|
||||
List<PsiElement> psiFiles = new ArrayList<PsiElement>(files.length);
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
for(VirtualFile file:files) {
|
||||
psiFiles.add(psiManager.findFile(file));
|
||||
}
|
||||
return new LocalSearchScope(psiFiles.toArray(new PsiElement[psiFiles.size()]), "Open Files");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user