mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
BAZEL-2297: search in non-indexable files should skip excluded dirs
Cherry-picked from IJ-CR-172078 GitOrigin-RevId: 1a780c083ebb56b116580e5d07169e7bcc3e7118
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b7204e435d
commit
897e6a555b
@@ -19,6 +19,7 @@ import com.intellij.workspaceModel.core.fileIndex.WorkspaceFileKind
|
|||||||
import com.intellij.workspaceModel.core.fileIndex.WorkspaceFileSet
|
import com.intellij.workspaceModel.core.fileIndex.WorkspaceFileSet
|
||||||
import com.intellij.workspaceModel.core.fileIndex.WorkspaceFileSetWithCustomData
|
import com.intellij.workspaceModel.core.fileIndex.WorkspaceFileSetWithCustomData
|
||||||
import com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexEx
|
import com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexEx
|
||||||
|
import com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileInternalInfo.NonWorkspace
|
||||||
import org.jetbrains.annotations.ApiStatus
|
import org.jetbrains.annotations.ApiStatus
|
||||||
|
|
||||||
|
|
||||||
@@ -51,17 +52,29 @@ private fun WorkspaceFileIndex.allIndexableFileSets(root: VirtualFile): AllFileS
|
|||||||
}
|
}
|
||||||
}.let { (recursive, nonRecursive) -> AllFileSets(recursive, nonRecursive) }
|
}.let { (recursive, nonRecursive) -> AllFileSets(recursive, nonRecursive) }
|
||||||
|
|
||||||
|
private fun WorkspaceFileIndexEx.isExcludedOrInvalid(file: VirtualFile): Boolean = runReadAction {
|
||||||
|
val info = getFileInfo(file, true, true, true, true, true, true)
|
||||||
|
when (info) {
|
||||||
|
NonWorkspace.EXCLUDED -> true
|
||||||
|
NonWorkspace.IGNORED -> true
|
||||||
|
NonWorkspace.INVALID -> true
|
||||||
|
NonWorkspace.NOT_UNDER_ROOTS -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresBackgroundThread
|
@RequiresBackgroundThread
|
||||||
private fun WorkspaceFileIndex.iterateNonIndexableFilesImpl(roots: Set<VirtualFile>, filter: VirtualFileFilter, processor: ContentIterator): Boolean {
|
private fun WorkspaceFileIndexEx.iterateNonIndexableFilesImpl(roots: Set<VirtualFile>, filter: VirtualFileFilter, processor: ContentIterator): Boolean {
|
||||||
for (root in roots) {
|
for (root in roots) {
|
||||||
val res = VfsUtilCore.visitChildrenRecursively(root, object : VirtualFileVisitor<Any?>() {
|
val res = VfsUtilCore.visitChildrenRecursively(root, object : VirtualFileVisitor<Any?>() {
|
||||||
override fun visitFileEx(file: VirtualFile): Result {
|
override fun visitFileEx(file: VirtualFile): Result {
|
||||||
ProgressManager.checkCanceled()
|
ProgressManager.checkCanceled()
|
||||||
|
if (isExcludedOrInvalid(file)) return SKIP_CHILDREN
|
||||||
val currentIndexableFileSets = allIndexableFileSets(root = file)
|
val currentIndexableFileSets = allIndexableFileSets(root = file)
|
||||||
return when {
|
return when {
|
||||||
!filter.accept(file) -> SKIP_CHILDREN
|
|
||||||
currentIndexableFileSets.recursive.isNotEmpty() -> SKIP_CHILDREN
|
currentIndexableFileSets.recursive.isNotEmpty() -> SKIP_CHILDREN
|
||||||
currentIndexableFileSets.nonRecursive.isNotEmpty() -> CONTINUE // skip only the current file, children can be non-indexable
|
currentIndexableFileSets.nonRecursive.isNotEmpty() -> CONTINUE // skip only the current file, children can be non-indexable
|
||||||
|
!filter.accept(file) -> SKIP_CHILDREN
|
||||||
!processor.processFile(file) -> skipTo(root) // terminate processing
|
!processor.processFile(file) -> skipTo(root) // terminate processing
|
||||||
else -> CONTINUE
|
else -> CONTINUE
|
||||||
}
|
}
|
||||||
@@ -107,6 +120,8 @@ private class NonIndexableFilesDequeImpl(private val project: Project, private v
|
|||||||
if (file in visitedRoots) continue
|
if (file in visitedRoots) continue
|
||||||
if (file in roots) visitedRoots.add(file)
|
if (file in roots) visitedRoots.add(file)
|
||||||
|
|
||||||
|
val workspaceFileIndex = WorkspaceFileIndexEx.getInstance(project)
|
||||||
|
if (workspaceFileIndex.isExcludedOrInvalid(file)) continue
|
||||||
val indexableFileSets = WorkspaceFileIndexEx.getInstance(project).allIndexableFileSets(file)
|
val indexableFileSets = WorkspaceFileIndexEx.getInstance(project).allIndexableFileSets(file)
|
||||||
|
|
||||||
if (indexableFileSets.recursive.isNotEmpty()) continue // skip the current file and their children
|
if (indexableFileSets.recursive.isNotEmpty()) continue // skip the current file and their children
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class SearchInNonIndexableTest() {
|
|||||||
|
|
||||||
val nonIndexable = baseDir.newVirtualDirectory("non-indexable").toVirtualFileUrl(urlManager)
|
val nonIndexable = baseDir.newVirtualDirectory("non-indexable").toVirtualFileUrl(urlManager)
|
||||||
baseDir.newVirtualFile("non-indexable/file1", "this is a file with some data".toByteArray())
|
baseDir.newVirtualFile("non-indexable/file1", "this is a file with some data".toByteArray())
|
||||||
|
|
||||||
baseDir.newVirtualFile("non-indexable/file2", "this is a file with some <DELETED>".toByteArray())
|
baseDir.newVirtualFile("non-indexable/file2", "this is a file with some <DELETED>".toByteArray())
|
||||||
|
|
||||||
val indexable = baseDir.newVirtualDirectory("indexable").toVirtualFileUrl(urlManager)
|
val indexable = baseDir.newVirtualDirectory("indexable").toVirtualFileUrl(urlManager)
|
||||||
@@ -62,9 +61,12 @@ class SearchInNonIndexableTest() {
|
|||||||
val indexableNonRecursive = baseDir.newVirtualDirectory("non-indexable/indexable-non-recursive").toVirtualFileUrl(urlManager)
|
val indexableNonRecursive = baseDir.newVirtualDirectory("non-indexable/indexable-non-recursive").toVirtualFileUrl(urlManager)
|
||||||
baseDir.newVirtualFile("non-indexable/indexable-non-recursive/non-indexable-beats-non-recursive-content", "this is a file with some data".toByteArray())
|
baseDir.newVirtualFile("non-indexable/indexable-non-recursive/non-indexable-beats-non-recursive-content", "this is a file with some data".toByteArray())
|
||||||
|
|
||||||
|
val excluded = baseDir.newVirtualDirectory("non-indexable/excluded").toVirtualFileUrl(urlManager)
|
||||||
|
baseDir.newVirtualFile("non-indexable/excluded/file-in-excluded", "this is a file inside an excluded directory".toByteArray())
|
||||||
|
|
||||||
project.workspaceModel.update("add non-indexable root") { storage ->
|
project.workspaceModel.update("add non-indexable root") { storage ->
|
||||||
storage.addEntity(NonIndexableTestEntity(nonIndexable, NonPersistentEntitySource))
|
storage.addEntity(NonIndexableTestEntity(nonIndexable, NonPersistentEntitySource))
|
||||||
storage.addEntity(IndexingTestEntity(listOf(indexable), emptyList(), NonPersistentEntitySource))
|
storage.addEntity(IndexingTestEntity(listOf(indexable), listOf(excluded), NonPersistentEntitySource))
|
||||||
storage.addEntity(NonRecursiveTestEntity(indexableNonRecursive, NonPersistentEntitySource))
|
storage.addEntity(NonRecursiveTestEntity(indexableNonRecursive, NonPersistentEntitySource))
|
||||||
}
|
}
|
||||||
VfsTestUtil.syncRefresh()
|
VfsTestUtil.syncRefresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user