GlobalSearchScope (ExcludeEntryDescription @NotNull [] descriptions, @NotNull Set<FileType> fileTypes, @NotNull Project project) { ManagingFS fs = ManagingFS.getInstance(); final Collection<VirtualFile> excludedFiles = Stream.of(descriptions) .flatMap(description -> { final VirtualFile file = description.getVirtualFile(); if (file == null) return Stream.empty(); if (description.isFile()) { return Stream.of(file); } else if (description.isIncludeSubdirectories()) { final Stream.Builder<VirtualFile> builder = Stream.builder(); VfsUtilCore.iterateChildrenRecursively(file, f -> !f.isDirectory() || fs.areChildrenLoaded(f), f -> { builder.accept(f); return true; }); return builder.build(); } else { return fs.areChildrenLoaded(file) ? Stream.of(file.getChildren()) : Stream.empty(); } }) .filter(f -> !f.isDirectory() && fileTypes.contains(f.getFileType())) .collect(Collectors.toList()); return GlobalSearchScope.filesWithoutLibrariesScope(project, excludedFiles); }